Ok when I compile this program it asks me for 'Gender' and if I put something other than 'F' or 'M' it should go straight to an 'Invalid Selection!' message that I have incorporated. What am I doing wrong?
If by "jump" you mean "gender" then there's nothing between the reading of the gender and the asking of the activity level and weight that would make the execution go to the invalid selection case.
You would have to do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
cout << "Enter Gender ('F') for Female and ('M') for Male: ";
cin >> gender;
gender = toupper(gender);
if( NotValidGender(gender) )
{
cout << "Invalid Selection!" << endl;
}
//maybe do the above in a loop until the user inputted a valid gender
cout << "Enter Your Activity Level (A/I): ";
...
No, the problem is obivous. You have to look at the program.
Take a look at this:
1 2 3 4 5 6 7 8 9
cout << "Enter Gender ('F') for Femaile and ('M') for Male: ";
cin >> gender;
level = toupper(level);
cout << "Enter Your Activity Level (A/I): ";
cin >> level;
cout << "Enter Current Weight: ";
cin >> weight;
Here you're reading the gender, the level activity and the weight. The program will read the level activity and the weight even if the gender is other the M or F.
So, if you want you program to read the gender, to see if it is M or F and if it's so, to make that operations and in the other case to stop the program and to print "Invalid Selection", you'll have to do like this:
The if-clause is just checking something. If the gender is not 'M' it will check the next if-clause. If it isn't 'F' either, it will print "Invalid Selection" in the next case: