### "Play again" loop acts like it works but doesn't

Hey guys and gals, just wondering if I can get some help with this. I'm a beginner and working on a game that asks if you want to play again after you're done. As it stands, it will ask if I want to play again, and prompt the first question in the game (Guesses a number between 1-100, always starts with 50, and asks if the user's number is higher, lower, or correct), but then the program stalls after that. It always runs fine the first time through, it's only when the loop repeats that I have trouble. Any help is much appreciated!!!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` ``````#include #include #include #include using namespace std; int main () { int number_guess; int min; int max; string guess; string play_again = "y"; while (play_again == "y") { number_guess = 50; min = 1; max = 101; guess = ""; cout << "Think of a number between 1 and 100." << endl; cout << "Is it " << number_guess << "? (h/l/c): "; getline (cin, guess); while (guess != "c") { // If too low if (guess == "h") { min = number_guess; number_guess = (max + min)/2; cout << "Is it " << number_guess << "? (h/l/c): "; cin >> guess; } // If too high else if (guess == "l") { max = number_guess; number_guess = (max + min)/2; cout << "Is it " << number_guess << "? (h/l/c): "; cin >> guess; } else if (guess == "c") { cout << "Yay!" << endl; break; } } cout << "Do you want to play again? (y/n): "; cin >> play_again; } return 0; } ``````
change `getline (cin, guess);` to `getline (cin>>ws, guess);` or to `cin>>guess;`

when you do `cin >> play_again;` you'll capture `"y"` but leave an `'\n'` in th e input buffer. Then comes the getline() that reads until a line break, so `guess' ends up being empty and you've got an endless loop.
`cin>>ws` will drop all the whitespace before performing the reading.

By the way, the condition on line 47 will always fail, ¿can you realise why?
Thank you, that fixed it! Is it the break statement? You're right, it would never read out the "Yay" even when the number was right, so I took out that whole elif statement and just moved the "yay" down out of the loop above the "Do you want to play again" line, because I figured if you'd gotten to that point your number was right anyway. I'm really, really new to this so I'm not exactly sure why line 47 was breaking everything.

Thanks again!
It's not because of the break statement but that's a good guess.