While loop not working as expected.

1
2
3
4
5
6
7
8
unsigned char response = 0;


while ((response != 1) || (response != 2) || (response !=3))
{
//validation check and enter new response
cin >> response;
};


I keep getting stuck, I've tried converting to AND, using the == instead of or but I still get the same problem. Any tips, the syntax isn't the problem...its the choice of syntax I think.

====
I've changed response from a char to an int. No difference.

I've changed the while parameters from above to ((response < 1) || (response > 3)) no luck.
Last edited on
change char to int(character representations of numbers have a completely different value than its integer counterpart), also you can use AND as a parameter as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>
using namespace std;
int main()
{
	unsigned int response = 0;


	while ((response != 1 && response != 2 && response !=3))
	{
		//validation check and enter new response
		cout << "Enter response ";
		cin >> response;
	}
	cout << "Finis";
	return 0;

}





Enter response 4
Enter response 7
Enter response 9
Enter response 2
Finis

Last edited on
I still get the recurrence if I enter a letter instead. Which means still not working as expected.
Last edited on
Topic archived. No new replies allowed.