Loop Problem

Started by
5 comments, last by Hammonjj 16 years, 10 months ago
if (quit != 'n' || quit != 'N' || quit != 'y' || quit != 'Y') {
	cout << "You did not enter a valid option. Please try again, Y for yes and N for no.\n\n";
	quit = end_program();
}
		
No matter what input I use this loop always executes. What I'm trying to do is say if quit does not equal n or N or y or Y then execute the loop, but not for when quit is equal to n, N, y, or Y. Thanks for the help.
James HammondUniversity of ColoradoDepartment of Computer Science
Advertisement
Check your logic. You want to "AND" them together.
... quit != 'n' && quit != 'N'...
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Further reading: De Morgan's laws.
Loop? What loop?

There is no spoon loop.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Judging by that minimal snippet of code, you also want to change your "if" to "while".
Quote:Original post by Hammonjj
quit != 'n' || quit != 'N'


This will always be true, no matter what character quit holds (because quit cannot hold two different values at the same time).
Thanks!

After seeing what I did wrong I hit myself. I feel kind of like an idiot.
James HammondUniversity of ColoradoDepartment of Computer Science

This topic is closed to new replies.

Advertisement