int getGuess(int gameNumber)
{
int guess, tries=1;
bool found = false;
cout<<"\nEnter your guess: ";
cin>>guess;
if(!found)
{
while( guess > 100 || guess < 0 || guess != gameNumber)
{
if(guess < gameNumber)
{
cout<<"That's too low !"<<endl;
}
elseif(guess > gameNumber)
{
cout<<"That's too high !"<<endl;
}
cout<<"Enter your guess: "<<endl;
cin>>guess;tries++;
if(tries==GAME_TRIES)
{
cout<<"You have run out of tries"<<endl;
cout<<"Number of tries = "<<tries<<endl;
cout<<"Game number is = "<<gameNumber<<endl;
cout<<"\n\n";
tries=0;
found=true;
guess=gameNumber;
}
}
}
else
{
cout<<"Congratulations! ! You have guessed the game number\n";
cout<<"Number of tries = "<<tries<<endl;
cout<<"Game number is = "<<gameNumber<<endl;
cout<<"\n\n";
tries=0;
}
return guess;
}
OUTPUT EXAMPLE:
Enter your guess: 6
That's too low
Enter your guess: 7
That's too low
Enter your guess: 8
That's too low
You have run out of tries
Number of tries = 3
Game number is = gameNumber(RANDOM NUMBER FROM MAIN)
I want to do this,
Enter your guess: 7
That's too high
Enter your guess: 7
You already guessed that
Enter your guess: