Where have I gone wrong?

I am simply trying to prompt a user to enter M for Male or F for Female. However, when I test run the program (what I've got so far below), any letter inputted is accepted and continues the program..? I am a beginner. Please advise. Thanks!

#include <iostream>

using namespace std;

int main()
{
char gender;
int maleBodyWeight;


cout << "Please Select Your Gender. Male(M) or Female(F): " << endl;
cin >> gender;
cout << endl;

if (gender == 'm' || 'M')
{
cout << "Please enter your current body weight: " << endl;
cin >> maleBodyWeight;

}
else
{

cout << "Please enter M for Male and F for Female" << endl;
}


return 0;
}
Your if statement to check if the variable "gender" is m does not work. The equality comparison evaluates before the or comparison- it checks if gender is lowercase m, or whether M exists (which is always true). The correct line would be:

if(gender == 'm' || gender == 'M')
Thank you very much for the explanation and correct line! I greatly appreciate this.
Topic archived. No new replies allowed.