I'm currently working on a fairly basic piece of code here. I'm attempting to check the user's input so that if it is anything other than a number as requested, an error message will pop up and a new input will be requested. I'm using a while loop that should be reset when the continue statement is hit, however it always ends up falling into an infinite loop repeating the error message if an there is an invalid input. Any help would be appreciated, thanks!
while (tester != 1){
cout << "Enter your answer: ";
cin >> userInput;
if (cin.fail()){ //check if user input is valid
cout << "Error: that is not a valid integer.\n";
continue; //continue skips to top of loop if user input is invalid, allowing another attempt
} else{
tester = 1; //Tester variable allows loop to end when good value input
}
}