i need to write program which,at the beginning program generates radom number in the range specified by the user(ask the user for the smallest and the biggest value).the user try to guess unknown number.program answers"to small"or "to big" if the user is wrong and if the user is succesfull,the program ask,whether the user want to play again.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
int min, max, random, guess; //Variables we need
cout << "Minimum?\n";
cin >> min;
cout << "Maximum?\n";
cin >> max; //Ask the user for the minimum and maximum numbers
random = (rand() % (max - min)) + min; //Make our random number
cout << "Have a guess\n";
while(guess != random)
{
cin >> guess; //Get their guess
if(guess > random) //If its too big...
{
cout << "Too big!\n";
bool tryagain;
cout << "Try again?\n"; //Ask them if they want to try again
cin >> tryagain;
if(!tryagain)
return 0; //No? Then end the program, otherwise continue the loop
}
if(guess < random) //If its too small...
{
cout << "Too small!\n";
bool tryagain;
cout << "Try again?\n"; //Ask them if they want to try again
cin >> tryagain;
if(!tryagain)
return 0; //No? Then end the program, otherwise continue the loop
}
}
cout << "Well done!"; /*The only time this will ever be reached
is if the loop ends without the program ending,
which can only happen when the
guess is equal the the random number*/
}