Problem: The counter for acceptable doesn't work upon entering values that should increase acceptable by 1. Instead it adds to unacceptable, it may have something to do with the {} braces however im not sure. Any Ideas? this is the only current problem, thanks pplz !
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, unacceptable_carbon = 0; int acceptable_hydro = 0, unacceptable_hydro = 0; int acceptable_nitro = 0, unacceptable_nitro = 0; int acceptable_nonmeth = 0, unacceptable_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){ if ( gas >= 5 ){ printf("Error please try again\n"); break;} if ( gas < 0 ){ printf("Error please try again\n"); break;} 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 unacceptable_carbon++; if (( distance > 80000 ) || ( years > 5 )) if (gas_emmissions < carbon_b) acceptable_carbon++; else unacceptable_carbon++; } if (gas == 2){ if (( distance <= 80000 ) || ( years < 5 )) if (gas_emmissions < hydro_a) acceptable_hydro++; else unacceptable_hydro++; if (( distance > 80000 ) || ( years > 5 )) if (gas_emmissions < hydro_b) acceptable_hydro++; else unacceptable_hydro++; } if (gas == 3){ if (( distance <= 80000 ) || ( years < 5 )) if (gas_emmissions < nitro_a) acceptable_nitro++; else unacceptable_nitro++; if (( distance > 80000 ) || ( years > 5 )) if (gas_emmissions < nitro_b) acceptable_nitro++; else unacceptable_nitro++; } if (gas == 4){ if (( distance <= 80000 ) || ( years < 5 )) if (gas_emmissions < nonmeth_a) acceptable_nonmeth++; else unacceptable_nonmeth++; if (( distance > 80000 ) || ( years > 5 )) if (gas_emmissions < nonmeth_b) acceptable_nonmeth++; else unacceptable_nonmeth++; } subtotal_c = acceptable_carbon + unacceptable_carbon; subtotal_h = acceptable_hydro + unacceptable_hydro; subtotal_n = acceptable_nitro + unacceptable_nitro; subtotal_nm = acceptable_nonmeth + unacceptable_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, unacceptable_carbon, subtotal_c); printf( "Hydrocarbons\t\t\t\t%d\t%d\t\t%d\n",acceptable_hydro, unacceptable_hydro, subtotal_h); printf( "Nitrogen oxides\t\t\t\t%d\t%d\t\t%d\n",acceptable_nitro, unacceptable_nitro, subtotal_n); printf( "Non-methane hydrocarbons\t\t%d\t%d\t\t%d\n\n",acceptable_nonmeth, unacceptable_nonmeth, subtotal_nm); printf( "\nPlease enter the number corresponding to the gas you require (0 to exit): "); scanf( "%d",&gas); } return 0; }



LinkBack URL
About LinkBacks


