Input validation issue

I am having a hard time figuring out why this gives me an infinite loop of "Please try again:" no matter what I input. I need it to display the error message only if a character is inputted but I cannot figure it out. This is the function it's a part of.

1
2
3
4
5
6
bool PlayAgain()
{
	bool playAgain = false;
	char answer;

}
Last edited on
while((response != 'y' || 'Y') || (response != 'n' || 'N'))

The " || 'y' " bits simply compare the value of 'Y' agains zero, hence it will always be true. Try changing that line to this:
while((response != 'y' && response != 'Y') && (response != 'n' && response != 'N'))

EDIT:
Also, I just noticed, 'response' is never declared and never modified. Try changing it to while((anwer != 'y' && answer != 'Y') && (answer != 'n' && answer != 'N'))
Last edited on
Thanks a lot!
Topic archived. No new replies allowed.