while 'variable char' is not 'char'

1
2
3
4
5
6
7
8
    cout << "Is your character Male or Female?" << endl;
    cout << "Male(m)/Female(f)/Other(?): ";
    cin >> gender;
        while (gender != 'm' || gender != 'f' || gender != '?') {
              cout << "Incorect character specified!" << endl;
              cout << "Please Re-Enter your coresponding gender letter: ";
              cin >> gender;
              }


Currently, the program runs as if the user has entered the correct character no matter what.
Am I missing something?

thanks
Last edited on
1
2
3
4
5
6
7
8
    cout << "Is your character Male or Female?" << endl;
    cout << "Male(m)/Female(f)/Other(?): ";
    cin >> gender;
        while (gender != 'm' && gender != 'f' && gender != '?') {
              cout << "Incorect character specified!" << endl;
              cout << "Please Re-Enter your coresponding gender letter: ";
              cin >> gender;
              }


|| vs &&, think about it, it's interesting sometimes.

Look up demorgan's law. That makes this sort of thing a little easier to think about sometimes.
Last edited on
*Made corrections*

It now works. Thank you a ton.

Upon reviewing DeMorgan's Law via Wikipedia, I still find it rather difficult to wrap my head around.

Logic Operations are quite fascinating.
Thank you again!
A variable can only have one value at a time right? So if it is one, then it isn't the others, thus the loop goes forever.
Topic archived. No new replies allowed.