While Loop Logic

can someone tell me where i am wrong with my logic?

The console asks for a char of 's' || 'c' || 't' || 'e' || 'n' || 'o' and if it is not one of these a while loop below shows up. But the while loop always implements even if it is one of those values.

while (x != 's' || 'c' || 't' || 'e' || 'n' || 'o') {
cout << "YOU BLEW IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
cout << "Enter the correct function id (s=sin, c=cos, t=tan, e=sec, n=csc, o=cot): ";
cin >> x;
if (x == 's' || 'c' || 't' || 'e' || 'n' || 'o') {
break;
}
}
Well first of all, if your going to write code please use code tags (<> button) as it makes it easier to read, but getting to your problem, since you are using a char you need to make it into an array and declare its position in that array because other wise your compiler will give you an error. Here is an example:
1
2
3
4
5
6
7
8
while (x[0] != 's' ||x[0]!= 'c' ||x[0]!= 't' ||x[0]!= 'e' ||x[0]!= 'n' ||x[0]!= 'o') {
   cout << "YOU BLEW IT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
	cout << "Enter the correct function id (s=sin, c=cos, t=tan, e=sec, n=csc, o=cot): \n";
	cin >> x;
	if (x[0]== 's' ||x[0]== 'c' ||x[0]== 't' ||x[0]== 'e' ||x[0]== 'n' ||x[0]== 'o') {
	break;
	}
	}

So when initiating the char variable as an array you can declare it as char x[1];

Please feel free to ask any questions if you are confused.
Why did you set it to an array?
Because otherwise it doesn't compile right 100% of the time. If you don't make it an array then you could make it a string but seeing as its only one letter it makes more sense to make it into an array.
Topic archived. No new replies allowed.