I wanted to have the loop closing when value x is 1, 2 or 3, it works if i write only x!=1 but with or operator i can't manage to make it work, thanks in advance
#include <iostream>
usingnamespace std;
int main (){
int x;
while((x!=1)||(x!=2)||(x!=3)){
cin >> x;
switch(x){
case 1: cout << "one is one" << endl;
break;
case 2: cout << "two is two" << endl;
break;
case 3: cout << "three is three" << endl;
break;
default: cout << x << " is not 1, 2 or 3" << endl;
break;
}
}
}
Line 7: You want the && operator, not the || operator.
BTW, the first time through the loop you're going to be comparing garbage because x is not initialized. Your condition may or may not work depending onb the value of the garbage.