I need to write a program that decides if you can apply for the job or not. After asking a series of questions (all the questions) the program then needs to print out whether you can apply or not.
Here are the requirments for the job
• 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 started this code and it compiles, but it prints out you may apply twice and sometimes even says you cannot apply, any help is greatly appreciated

#include <iostream>
#include <string>
using namespace std;
int main ()
{
int age, pushups;
string firstname,lastname, military, sex;

cout << "What is your full name? ";
	cin >> firstname >> lastname;
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 you <m>ale of <f>emale? ";
	cin >> sex;

if ((age >= 18 && age <= 30 && sex == "m") || (age >= 18 && age <= 35 && sex == "m" && pushups < 50 || military == "yes"))
{
	cout << "You can apply" << endl;
}
if ((age >= 18 && age <= 32 && sex == "f") || (age >= 18 && age <= 40 && sex == "f" && pushups < 30 || military == "yes"))
{

	cout << "You can Apply" << endl;
}

else if (age <=18 || age >= 40 ||pushups > 50 )
{	
	cout << "You MAY NOT apply";
}
}
tux4life commented: For using code tags on first post :) +11

put an else between the first two if statements, like you did between the last two statements.

A few things: first of all, make the second if statement else-if; second, make the last else-if statement else. Also, pushups should be >50/>30. You should be more carefull with your brackets too:

if ((age >= 18 && age <= 30 && sex == "m") || (age >= 18 && age <= 35 && sex == "m" && (pushups >= 50 || military == "yes")))

Aso, you can use the distributive law to simplify the expression with sex == "m" and age >= 18 .

if (age >= 18 && sex == "m" && (age <= 30 || (age <= 35 && (pushups >= 50 || military == "yes"))))

Though this is not necessary.

thanks guys, it works perfect now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.