Easy Question

I want to not let the user proceed if they have entered anything that is NOT the character 'a', 'b', or 'c'.. When I run it and put in g, or something that is != to what I have in the condition of the While loop the program says invalid, try again..but when I put in 'a' when I am trying again it says "Invalid try again:" and then everything from that point on is invalid.. -_- What am I doing wrong?

1
2
3
4
5
6
7
8
9
char command;

cout << "enter stuff..: "; cin >> command;

while(command != 'a' || 'b' || 'c')
{
   cout << "invalid..try again: "; cin >> command;
}
it should be

5
6
7
8
while(command != 'a' && command != 'b' && command != 'c')
{
    ...
}



This means basically to run while it is not a and it is not b and it is not c. In other words anything but a, b, or c.

*fixed code tags
Last edited on
closed account (2UD8vCM9)
I would just use a string and using getline(cin,stringname);
Topic archived. No new replies allowed.