Part 1: Nested if statements Problem description In this exercise you will be us
ID: 3552742 • Letter: P
Question
Part 1: Nested if statements
Problem description
In this exercise you will be using nested if statements to determine if a person qualifies for financial aid.
Write the source code for a program that asks the user if they are an
undergraduate student. They enter y if they are an undergraduate and n if they are not an
undergraduate student. If the answer is n then they do not qualify for financial aid. If the answer is y
they are then asked to enter their income level as an integer. If their income is equal to or below
$15,000 then they qualify for $1000 in financial aid, but if their income is greater, they only qualify for
$500 in financial aid.
The input and output should look similar to this (the bolded parts represent inputs by the user). These
are three sample runs. You also need to test error conditions.
Run # 1
Are you an undergraduate student? y [Enter]
What is your current yearly income? 15000 [Enter]
You qualify for $1000 in financial aid.
Run # 2
Are you an undergraduate student? y [Enter]
What is your current yearly income? 15001 [Enter]
You qualify for $500 in financial aid.
Run # 3
Are you an undergraduate student? n [Enter]
You do not qualify for financial aid
As shown above, make sure you run the program with input values that only qualify for $500 in financial
aid and with input values that do not qualify for financial aid.
Your program should check the answer to the "Are you an undergraduate student?" question to make
sure it is either Y or N. If it is any other value, output an error message and then end the program.
If the student is an undergraduate, you will ask for their income. If their income is less than 0, output an
error message telling them that the income must be greater than or equal to 0 and then end the
program.
Explanation / Answer
Q1..
#include<iostream>
using namespace std;
int main()
{
char ch;
int s;
while(1)
{
cout<<"ARE YOU AN NDERGRADUATE PRESS ENTER FOR Y OR N : ";
cin>>ch;
if(ch=='Y' || ch=='y')
{
while(1)
{
cout<<"ENTER YOUR SALARY in $ : ";
cin>>s;
if(s>=0 && s<15000)
{
cout<<"CONGRATULATIONS!!! YOU ARE ELIGIBLE FOR 1000$ FINANCIAL AID "<<endl;
break;
}
else
{
if(s>15000)
{
cout<<"CONGRATULATIONS!!! YOU ARE ELIGIBLE FOR 1000$ FINANCIAL AID "<<endl;
break;
}
else
{
cout<<"SALARY MUST BE GRATER THAN 0 "<<endl;
}
}
}
}
else
{
if( ch== 'N' || ch=='n')
{
cout<<"YOU DO NOT QUALIFY FOR FINANCIAL AID "<<endl;
break;
}
else
{
cout<<"INVALID ENTRY"<<endl;
}
}
}
system("pause");
}