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!!!
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.