How do you write two separate functions using rand() to randomly pick a number 1-12 and then write one to randomly pick a character(the five math operators) without being in the main ().
How do you write two separate functions using rand() to randomly pick a number 1-12 and then write one to randomly pick a character(the five math operators) without being in the main ().
PHP Code:
#include <iostream.h> //cout,cin
#include <stdlib.h> //srand(), rand()
#include <time.h> //time()
char Operators[] = {'+','-','*','/','^'};
char GetRandomOperator()
{
return Operators[rand() % 5];
}
int GetRandomNumber(long Low, long High)
{
if(Low >= High)
return 0;
return (rand() % (High - Low + 1)) + Low;
}
void main()
{
srand(time(NULL));
cout<<"A random operator: "<<GetRandomOperator()<<"\nA random number between 1 and 12: "<<GetRandomNumber(1,12)<<"\n";
cin.get();
}
Last edited by XSquared; 07-07-2002 at 08:25 PM.