This is my program:

There is a secret government organization called PIB which only accepts recruits who fit
their criteria (shown below). If you fit any of the combinations of criteria, then you can
apply to work for PIB. Write a program which asks the user appropriate questions (ask
all the questions up front) and then determines if the candidate is acceptable. Use the
screen shots as a guide.
Here are the rules:

• If you are male between the ages of 18 and 30 (inclusive) you may apply.
• If you are female between the ages of 18 and 32 (inclusive) you may apply.
• If you are male between the ages of 18 and 35 (inclusive) and either were in the
military or you can do at least 50 pushups in a row you may apply.
• If you are female between the ages of 18 and 40 (inclusive) and either were in the
military or you can do at least 30 pushups in a row you may apply.
• No one else is eligible.

I have this so far:

#include <iostream>
#include <string>
using namespace std;
int main ()
{
int age;
int pushups;
string name;
string gender = "m";
string answer = "yes";

while (answer == "yes")
{
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 >> answer;

cout << "How many pushups can you do in a row? ";
cin >> pushups;

cout << "Are you <m>ale or <f>emale? ";
cin >> gender;

}
}

I need my program to out put the message: Yes, <name>, you may apply.....If they meet the criteria above. If they don't meet the criteria, then it needs to say "Sorry, <name>, you are not eligible."

I have been working on it all day and I can't seem to figure out a way to compare everything. It has to be in a while loop with if statements.

I just decided to not use a loop because it is unnecessary. Does this program look good?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
int age;
int pushups;
string name;
string gender;
string answer;

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 >> answer;

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 <= 32) && (gender == "f"))) ||
	((gender == "m") && (age >= 18) && (age <= 35) && (answer == "yes" || pushups >=50))) ||
	((gender == "f") && (age >= 18) && (age <= 40) && (answer == "yes" || pushups >=30)))

cout << "Yes, " << name << ", you may apply." << endl;

else
cout << "Sorry, " << name << ", you are not eligible." << endl;


}

Ok, I like this style more (it's the same concept), but it's just a suggestion:

bool male = (gender == "m");
bool is_for_army;
bool was_in_army = (answer == "yes");

if (age>=18){
    if (male){
        if (age <= 30) is_for_army = true;
        else if (age <= 35 && (was_in_army || pushups >=50)) is_for_army = true;
        else is_for_army = false;
    }
    else{
        if (age <= 32) is_for_army = true;
        else if (age <= 40 && (was_in_army || pushups >=30)) is_for_army = true;
        else is_for_army = false;
    }
}
else is_for_army = false;

if (is_for_army)
    cout << "Yes, " << name << ", you may apply." << endl;
else
    cout << "Sorry, " << name << ", you are not eligible." << endl;

Yes, yours does look much nicer. I always seem to write in a sloppy manner which will hurt me with longer programs. My teacher gives us examples, which never seem to help, and he didn't use bools so neither did I. I really appreciate the help Sci@phy. I'm sure I'll be posting more in the near future. These assignments are getting difficult for me.

Yes, yours does look much nicer. I always seem to write in a sloppy manner which will hurt me with longer programs. My teacher gives us examples, which never seem to help, and he didn't use bools so neither did I. I really appreciate the help Sci@phy. I'm sure I'll be posting more in the near future. These assignments are getting difficult for me.

You don't have to use bools for simple stuff, like:

if (a >= b) //code here
else //code here

I used bool for two reasons:
1. To assing values to stuff that is calculated more than once
You had four checks if (age >= 18) and each time computer has to calculate once again if it is true (to protect myself from experts: maybe :) ). In this way it calculates only once.
2. To make code more readable
There's no much explanation to this, but as I said earlyer, don't overuse bools

This article has been dead for over six months. Start a new discussion instead.