The following is a snippet from an application program. It ran fine through a few tests but when I used a 19 year old male (which should have satisfied the very first condition and been done with it) I additionally have the else statement output. Essentially, this input ends up satisfying the if and returning the proper output, but also the else returning that output as well. Silly program.
Code:
int age, pushups;
string name, military;
char gender;
cout << "What is your full name? "; getline (cin, name);
cout << "How old are you? "; cin >> age;
cout << "Were you ever in the military (yes/no)? "; cin >> military;
cout << "How many pushups can you do in a row? "; cin >> pushups;
cout << "Are (m)ale or (f)emale? "; cin >> gender;
if ((age >= 18 && age <= 30 && gender == 'm')||(age >= 18 && age <= 35 && gender == 'm' && (military == "yes" || pushups >= 50)))
{
cout << "Yes, " << name << ", you may apply." << endl;
}
if ((age >= 18 && age <= 32 && gender == 'f')||(age >= 18 && age <= 40 && gender == 'f' && (military == "yes" || pushups >= 30)))
{
cout << "Yes, " << name << ", you may apply." << endl;
}
else cout << "Sorry, " << name << ", you are not eligible." << endl;
Don't ask what this application is for by the way...it's super secret!