samedi 14 mars 2020

Even if the if function conditions are not met, the code is running? [closed]

Hello I am in an intro C++ class and am struggling with this code. Although my project runs fine, the following if statement will always run regardless if the condition is met or not.

cout << "Enter gender. F for female, M for male: ";
cin >> gender;
gender = toupper(gender);
if ( gender != 'F' || gender != 'M' )
{
    cout << "Please re-enter gender. F for female, M for male: ";
    cin >> gender;
}

If gender is equal to 'F' or 'M' it will run, and if it isn't equal to 'F' or 'M', then it will also run. Even though at the end of the day my project runs fine and does what it needs to do, I must be doing something wrong here. Any help would be appreciated, thanks in advance.

Aucun commentaire:

Enregistrer un commentaire