A C++ built in random function generates random numbers in a given range. write a game program that asks a user to enter any value between 1 and 10 and the program should generate a value between 1 and 10 using a C++ random function and compare the value entered by a user to the value generated by the computer if the value generated by the computer if the values are equal the program should display "you have won" and "you lost" if they are not equal.
int getUserNumber()
{
int number;
cin >> number;
return number;
}
int getComNumber()
{
return ( 1 + rand()% 10 );
}
int main()
{
int user = getUserNumber();
int com = getComNumber();
if(user == com )
{
//to do
}
else
{
//to do
}
return 0;
}
cnoeval haha funny...its not an assignment I came across that question in some book and I dint know were to start from and a the c++ function random generator,that gets random numbers.
okie I tryd to study that one posted by ericool but when compiring it says "rand" needs a prototype so comparing to the info on the link you posted am not sure how to hundle the "rand issue or sorting everything out