Reputation: 37
int guess_number = (gen() % 1000);
cout << guess_number;
int number = 0;
cout << "Number:";
cin >> number;
do
{
if (number>guess_number)
{
cout << "Too High"<<"\n";
cin >> number;
}
else if (number<guess_number)
{
cout << "Too Low"<< "\n";
cin >> number;
}
} while (number != guess_number);
int again=0;
cout << "Wanna Play Again!";
cin >> again;
I'm making a guessing game, but must loop the game if the player answers 1 after "Wanna Play Again!" I'am working with if,for,do, switch, and while statements. Its an assignment I was given and I just can't seem to figure out exactly how to loop the entier statement. I have made several attempts, but it either exits the program or continually prints "Wanna Play Again!".
Upvotes: 1
Views: 161
Reputation: 540
How about wrapping the existing do/while with a another for the play again condition ?
int again =0;
do{
do{
//existing code
} //end inner while
cout << "Wanna Play Again?";
cin >> again;
} while(again != 0); //or whatever makes sense for the condition
Upvotes: 1