Answer to Question #6826 in C++ for Mohd Hanif Bin Mohammad Halmi

Question #6826
You, as a programmer are required to develop a C++ program that checks the status of Air Pollution Index (API) based on the table below:

API Air Quality Status
0 – 50 Good
51 – 100 Average
101 – 200 Not healthy
201 – 300 Very unhealthy
301 – 500 Danger
over 500 Declare critical condition

If the user input API value less than zero, display a message “API not valid“. You must use a loop so that the program will be looping until the user chooses not to continue. Your program should have a function named IPU_CATEGORY that will check the API category by using if-else statement and then display the result of the air quality status.
1
Expert's answer
2012-02-23T11:00:02-0500
#include <iostream>

using namespace std;

char *IPU_CATEGORY(int value)
{
if(value<0)
{
& return "API not valid";
}
else if(value>=0 && value<=50)
{
& return "Good";
}
else if(value>=51 && value<=100)
{
& return "Avarage";
}
else if(value>=101 && value<=200)
{
& return "Not healthy";
}
else if(value>=201 && value<=300)
{
& return "Very unhealthy";
}
else if(value>=301 && value<=500)
{
& return "Danger";
}
else if(value>500)
{
& return "Declare critical condition";
}


}

int main()
{
int value=0;
while(1)
{
& cin>>value;
& cout<<IPU_CATEGORY(value)<<endl;
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS