I'm building a text based video game. The way the user interacts with the game is through menus, and entering a integer to select an option in the menus. If an invalid character is entered(i.e. a string, or a char that isn't 1-5), if entered the program asks the user to reenter their input, until their input is valid. I can't figure out why it's looping 5 times the user inputs a bad value. Heres a snippit of my code, and output/input.
[edit] took out code, it was too long and I reposted it.
I had to make that variable a char because if it's a integer when cin >> menuChoice happens, then if the user inputs a string or a char, the program will freakout and not allow the user to reenter a integer value for menuChoice. I made it a char to avoid this problem, and the user that still enter integers...
Ok so i figured out that the number of times the error message is printed is number of char's in whatever the user types in. Here's an example of the output. Also I changed the way isValidInput is.
I figured it out.... I just changed everything to string and it works now. It was looping because it could only clear one char at a time, so it I typed asda it would take 4 loops to check all 4 of those characters. Thanks for the response king214
Because IF the user enter 's' or 'asdasd' then the variable that is a integer would be assigned as a string, and it then messes up the variable not letting it be reassigned when the user reenters a value.