Write a program that interacts with the user like this: (1) Carbon monoxide (2)
ID: 3632915 • Letter: W
Question
Write a program that interacts with the user like this:
(1) Carbon monoxide
(2) Hydrocarbons
(3) Nitrogen oxides
(4) Nonmethane hydrocarbons
Enter the pollutant number>> 2
Enter the number of grams emitted per mile>> 0.35
Enter odometer reading>> 40112
Emissions exceed permitted level of 0.31 grams/mile.
Use this table of emissions:
Emissions First 50,000miles Second 50,000 miles
carbonmonoxide 3.4grams/mile 4.2 grams/mile
hydrocarbons 0.31grams/mile 0.39 grams/mile
nitrogenoxides 0.4grams/mile 0.5 grams/mile
nonmethane hydrocarbons 0.25grams/mile 0.31 grams/mile
please focus I need program in c !!!! not C++or java:((
please I need full right answer BTW
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int pollutantNum;
long odometerReading;
float emissions;
char ch;
float first50K[4] = {3.4, 0.31, 0.4, 0.25};
float second50K[4] = {4.2, 0.39, 0.5, 0.31};
ch = 'n';
while(1>0)
{
printf("(1) Carbon Monoxide ");
printf("(2) Hydrocarbons ");
printf("(3) Nitrogen oxides ");
printf("(4) Nonmethane hydrocarbons ");
printf(" Enter the pollutant number>>");
scanf("%d",&pollutantNum);
printf(" Enter the number of grams emitted per mile>>");
scanf("%f",&emissions);
printf(" Enter odometer reading>>");
scanf("%ld",&odometerReading);
if(pollutantNum >= 1 && pollutantNum<= 4)
{
if(odometerReading <= 50000)
{
if(emissions > first50K[pollutantNum-1])
printf(" Emissions exceed permitted level of %f grams/mile.",first50K[pollutantNum-1]);
}
else
{
if(emissions > second50K[pollutantNum-1])
printf(" Emissions exceed permitted level of %f grams/mile.",second50K[pollutantNum-1]);
}
}
else
{
printf(" Invalid pollutant number entered");
}
printf(" Do you want to check another pollutant(enter Y/N)?");
fflush(stdin);
ch = getchar();
if(ch == 'n' || ch == 'N')
break;
}
system("PAUSE");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.