Code:
#include <stdio.h>
int main(){
int subtotal_c = 0, subtotal_h = 0, subtotal_n = 0, subtotal_nm = 0;
int gas, distance, gas_emmissions, years;
int acceptable_carbon = 0, unnacceptable_carbon = 0;
int acceptable_hydro = 0, unnacceptable_hydro = 0;
int acceptable_nitro = 0, unnacceptable_nitro = 0;
int acceptable_nonmeth = 0, unnacceptable_nonmeth = 0;
double carbon_a = 2.13;
double carbon_b = 2.63;
double hydro_a = 0.19;
double hydro_b = 0.24;
double nitro_a = 0.25;
double nitro_b = 0.31;
double nonmeth_a = 0.16;
double nonmeth_b = 0.19;
printf( "**************** Welcome To The Emmission Calculation Program ****************\n\n" );
printf( "(1) Carbon monoxide\n");
printf( "(2) Hydrocarbons\n");
printf( "(3) Nitrogen oxides\n");
printf( "(4) Non methane hydrocarbons\n");
printf( "\nPlease enter the number corresponding to the gas you require (0 to exit): ");
scanf( "%d",&gas);
while (gas != 0){
printf( "\nPlease enter the distance from the source: ");
scanf( "%d",&distance);
printf( "\nPlease enter number of years: " );
scanf( "%d", &years);
printf( "\nPlease enter the level of gas emmissions: ");
scanf( "%f",&gas_emmissions);
if (gas == 1){
if (( distance <= 80000 ) || ( years < 5 ))
if (gas_emmissions < carbon_a)
acceptable_carbon++;
else
unnacceptable_carbon++;
if (( distance > 80000 ) || ( years > 5 ))
if (gas_emmissions < carbon_b)
acceptable_carbon++;
else
unnacceptable_carbon++;
}
if (gas == 2){
if (( distance <= 80000 ) || ( years < 5 ))
if (gas_emmissions < hydro_a)
acceptable_hydro++;
else
unnacceptable_hydro++;
if (( distance > 80000 ) || ( years > 5 ))
if (gas_emmissions < hydro_b)
acceptable_hydro++;
else
unnacceptable_hydro++;
}
if (gas == 3){
if (( distance <= 80000 ) || ( years < 5 ))
if (gas_emmissions < nitro_a)
acceptable_nitro++;
else
unnacceptable_nitro++;
if (( distance > 80000 ) || ( years > 5 ))
if (gas_emmissions < nitro_b)
acceptable_nitro++;
else
unnacceptable_nitro++;
}
if (gas == 4){
if (( distance <= 80000 ) || ( years < 5 ))
if (gas_emmissions < nonmeth_a)
acceptable_nonmeth++;
else
unnacceptable_nonmeth++;
if (( distance > 80000 ) || ( years > 5 ))
if (gas_emmissions < nonmeth_b)
acceptable_nonmeth++;
else
unnacceptable_nonmeth++;
}
subtotal_c = acceptable_carbon + unnacceptable_carbon;
subtotal_h = acceptable_hydro + unnacceptable_hydro;
subtotal_n = acceptable_nitro + unnacceptable_nitro;
subtotal_nm = acceptable_nonmeth + unnacceptable_nonmeth;
printf( "\n*********************** These are the results: ***********************\n\n");
printf( "\t\t\t\tAcceptable Unacceptable Sub Totals");
printf( "\nCarbon monoxide\t\t\t\t%d\t%d\t\t%d\n",acceptable_carbon, unnacceptable_carbon, subtotal_c);
printf( "Hydrocarbons\t\t\t\t%d\t%d\t\t%d\n",acceptable_hydro, unnacceptable_hydro, subtotal_h);
printf( "Nitrogen oxides\t\t\t\t%d\t%d\t\t%d\n",acceptable_nitro, unnacceptable_nitro, subtotal_n);
printf( "Non-methane hydrocarbons\t\t%d\t%d\t\t%d\n\n",acceptable_nonmeth, unnacceptable_nonmeth, subtotal_nm);
}
return 0;
}
BOOYA!