verify input is a character

Quick question. My problem is that when someone enters an integer or non valid char, the error statement "Invalid entry please try again" is printed and goes through the loop asking the user if they want to keep a log. But when someone enters 2 integers for example, the error statement is printed 2 times before asking the user if they want to keep log. If the user enters 3 integers (234), the error statement is printed 3 times, and so on and so on. How can i fix this problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
do{
		cout << "\tDo you want to keep a log? (Y/N): ";
		cin >> answer;
		cout << endl;
	
	
		}while(checkanswer(answer) == false);


bool checkanswer(char ans)
{
	if((ans == 'y') || (ans == 'Y') || (ans =='n') || (ans == 'N'))
		return true;
	else
	{
		cout << "\tInvalid Entry, Please try again!\n\n";
	}
	return false;
}
make answer of type std::string, then simply check if the string contains invalid characters
Topic archived. No new replies allowed.