Forgive me if this has been asked and answered. I have searched the forums and could not find an answer.
I am a newbie to programming and have been going through the tutorials and am having a issue with my play again loop.
Here is my code:
The program compiles and runs -- the first time. When it gets to the hilighted part of the code it asks
using namespace std;
char name, answer, playAgain;
cout<<"please enter your first name: ";
cout<<"hello " << name <<"\n";
cout<<"did you have a good day? yes/no " ;
cin.getline ( answer, 4 );
( strcmp ( answer, "yes" ) == 0)
cout<< "I am so glad you had a good day" <<endl;
cout<< "I am sorry you had a bad day" <<endl;
cout<<"Would you like to play a game? yes/no ";
cin.getline (answer, 4 );
if (strcmp (answer, "yes") ==0)
cout<< "Great, this game is find the number " <<endl;
cout<< "The number will be between 0 and 100" <<endl;
cout<< "You have 8 tries " <<endl;
while(guess!=number && trycount<8)
cout<<"Please enter a guess: ";
if(guess<number) cout<<"Too low"<<endl;
if(guess>number) cout<<"Too high"<<endl;
cout<<"You guessed the number" <<endl;
cout<<"Sorry, the number was: "<<number <<endl;
cout<<"would you like to play again? yes/no" <<endl;
cin.getline (playAgain, 4);
while (strcmp (playAgain, "yes") == 0);
// cin.getline (playAgain, 4);
cout<<"Thanks for playing ";
cout<< "OK see you next time" ;
"would you like to play again? yes/no
Thanks for playing"
It never does go back to the game part of the code. As you can see, I have tried putting cin.getline(playAgain) both above and below the while statement and get the same result.
I know it is something easy but I can not figure out what I am doing wrong.
Thanks in advance for any insight you might be able to provide