==> this is my pesudocode code for an assignment. i stayed up all last nit with minimal success trying to code it into C. I do not want someone to complete the assignment for me, but would be very greatful if someone could start me off in the right track... starting is my biggest problem(and the fact that i will miss my next lecture due to wedding on that day, is going to be suckie- but will hopefully be a great day)
thanks anyone that would be of help

==> PROBLEM: basically to input a pollutant number, input amount of gas grams emmitted pkm, input distance from source (aceptable distance limits case1; <80,00km, case 2; >80,000 <160,000.... gas grams emmitted change with these two cases, evident below.) program will keep asking for these untill 0 is entered, then display summary.

Calculate_Acceptable_Unacceptable_Pollutants

Defining the table

Defining the variables

distance_source = 0
gas_amount_pkm = 0
gms_amount_pkm_temp = 0
pollutant_no = 0

Defining the counters

Display pollutant names and numbers
1. Carbon Monoxide
2. Hydrocarbons
3. Nitrogen oxides
4. Non methane hydrocarbons

IF pollutant (!= 0, 1, 2, 3,4)
Then display message (Please choose a correct number)

WHILE(pollutant number < 5 ) (possibally DO WHILE instead)

Prompt user for pollutant number

if(pollutant number is equal to 1)
prompt user for amount of gas grams pkm
read amount of gas grams pkm

prompt user for distance from source

if( distance > 80000 )

if( gas_amount_pkm > 2.63 )
display message(Carbon Monoxide emissions exceeds level of 2.63)

else if (gas_amount_pkm < 2.63 )
display message(Carbon Monoxide emissions are acceptable)

if( distance < 80000 )

if (gas_amount_pkm > 2.13 )
display message(Carbon Monoxide emissions exceeds level of 2.13)

else if (gas_amount_pkm < 2.13 )
display message(Carbon Monoxide emissions are acceptable)

Calculate Subtotal

SubTot_Carmonoxide = Accept_Carmonoxide + Unaccept_Carmonoxide
-------------------------------------------------------------------------------------------------
else if(pollutant number is equal to 2)

prompt user for amount of gas grams pkm
read amount of gas grams pkm

prompt user for distance from source

if( distance > 80000 )

if(gas_amount_pkm > 0.24 )
display message(Hydrocarbon emissions exceeds level of 0.24)

else if (gas_amount_pkm < 0.24 )
display message(Hydrocarbon emissions are acceptable)

if( distance < 80000 )

if(gas_amount_pkm > 0.19 )
display message(Hydrocarbon emissions exceeds level of 0.19)

else if (gas_amount_pkm < 0.19 )
display message(Hydrocarbon emissions are acceptable)

Calculate Subtotal

SubTot_Hydrocarbon = Accept_Hydrocarbon + Unaccept_Hydrocarbon

-----------------------------------------------------------------------------------------
else if(pollutant number is equal to 3)
prompt user for amount of gas grams pkm
read amount of gas grams pkm

prompt user for distance from source

if( distance > 80000 )

if(gas_amount_pkm > 0.31 )
display message(Nitrogen oxide emissions exceeds level of 0.31)

else if (gas_amount_pkm < 0.31 )
display message(Nitrogen oxide emissions are acceptable)

if( distance < 80000 )

if(gas_amount_pkm > 0.25 )
display message(Nitrogen oxide emissions exceeds level of 0.25)

else if (gas_amount_pkm < 0.25 )
display message(Nitrogen oxide emissions are acceptable)

Calculate Subtotal

SubTot_Nitrogen = Accept_Nitrogen + Unaccept_Nitrogen

-----------------------------------------------------------------------------------------------

else if(pollutant number is equal to 4)
prompt user amount of gas grams pkm
read amount of gas grams pkm

prompt user for distance from source

if( distance > 80000 )

if(gas_amount_pkm > 0.19 )
display message(Non_methane emissions exceeds level of 0.19)
else if (gas_amount_pkm < 0.19 )
display message(Non_methane emissions are acceptable)

if( distance < 80000 )

if(gas_amount_pkm > 0.16 )
display message(Non_methane emissions exceeds level of 0.16)

else if (gas_amount_pkm < 0.16 )
display message(Nonmethane emissions are acceptable)

Calculate Subtotal

SubTot_Nonmethane = Accept_Non_methane + Unaccept_Non_methane

---------------------------------------------------------------------------------------------

else if(pollutant number is <= 0 )

clear Screen

display Summary

Calculate Total Acceptable
Tot_accept = Accept_Car_monoxide + Accept_Hydro_carbon + Accept_Nitrogen + Accept_Non_methane

Calculate Total unacceptables
Tot_unaccept = Unaccept_Car_monoxide + Unaccept_Hydrocarbon + Unaccept_Nitrogen + Unaccept_non_methane

Calculate Total
Total = SubTot_Car_monoxide + SubTot_Hydro_carbon + SubTot_Nitrogen + SubTot_Non_methane

ENDWHILE
END

2. Why don't you post the code that you wrote last night, and we'll give you tips on how to improve it. We aren't into the whole 'writing code for others' thing.

3. Code:
```#include <stdio.h>
#include <stdlib.h> /*for exit funcion,& strtol*/

int main(void){
int distance_source, gas_amount_pkm, gms_amount_pkm_temp, pollutant_no,long_input;
char *loc; /*for strtol*/

printf("%s\n","1. Carbon Monoxide\n
2. Hydrocarbons\n
3. Nitrogen oxides\n
4. Non methane hydrocarbons");
if((fgets(input,sizeof input,stdin))==NULL){
printf("error occured getting input\n");
exit(1);
}
long_input=strtol(input,&loc,0);```
is that a start you can use or do you need more help?

4. ## maybe a better way to describe it

hi, thansk for your reply... im only in first yr programming and the program is really only meant to contain IF / ELSE statements and DO WHILE statement (while pollutant != 0) (note their are 4 pollutants, 0 is the end of file command aka; display summary)

The acceptable pollutant values are
<80000 >80000
carbon_monoxide 2.13 2.63
hydrocarbons 0.19 0.24
Nitrogen oxides 0.25 0.31
Non methane 0.16 0.19

(Half pseudocode half C) --- thats why im looking for help - thanks anyone

begin

IF pollutant == 1
printf amount of gas grams pkm
scanf amount

printf distance from source
scanf distance

IF ( amount > 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)
IF (amount < 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)

IF pollutant == 2
printf amount of gas grams pkm
scanf amount

printf distance from source
scanf distance

IF ( amount > 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)
IF (amount < 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)

IF pollutant == 3
printf amount of gas grams pkm
scanf amount

printf distance from source
scanf distance

IF ( amount > 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)
IF (amount < 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)

IF pollutant == 4
printf amount of gas grams pkm
scanf amount

printf distance from source
scanf distance

IF ( amount > 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++;(counter)
IF (amount < 80000)
IF (emitted > accepted value)
unacceptable++; (counter)
IF (emmitted < accepted value)
acceptable++; (counter)

If (pollutant == 0)

printf acceptable;
printf unnacceptable;

return

6. First thing I see is is the same code repeated multiple times based on the value of pollutant. I didn't look close but I didn't notice any real difference in the if's. Use the same code and where the value of pollutant actually causes a difference in the computations, put the if's there.

Originally posted by jereland
im only in first yr programming and the program is really only meant to contain IF / ELSE statements and DO WHILE statement (while pollutant != 0) (note their are 4 pollutants, 0 is the end of file command aka; display summary)
A first year programmer has learned enough to start this program, as suggested. Post code.

Spam deleted

8. After working all afternoon i am close to completion there is a few logic errors that i need to work out but im close!

and ideas?

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;
int unnacceptable_carbon = 0;
int acceptable_hydro = 0;
int unnacceptable_hydro = 0;
int acceptable_nitro = 0;
int unnacceptable_nitro = 0;
int acceptable_nonmeth = 0;
int 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( "\nPlease enter the number corresponding to the gas you require: ");
scanf( "%d",&gas);

printf( "\nPlease enter the distance from the source: ");
scanf( "%d",&distance);

if (distance == 80000){
printf( "The distance must be greater or less than 80000 ");
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");
printf( "\t\t\t\tAcceptable   Unacceptable   Sub Total");
printf( "\nCarbon monoxide\t\t\t\t%d\t%d\n",acceptable_carbon, unnacceptable_carbon);
printf( "Hydrocarbons\t\t\t\t%d\t%d\n",acceptable_hydro, unnacceptable_hydro);
printf( "Nitrogen oxides\t\t\t\t%d\t%d\n",acceptable_nitro, unnacceptable_nitro);
printf( "Non-methane hydrocarbons\t\t%d\t%d\n",acceptable_nonmeth, unnacceptable_nonmeth);

return 0;
}```

9. Code:
```subtotal_c = acceptable_carbon + unnacceptable_carbon
subtotal_h = acceptable_hydro + unnacceptable_hydro
subtotal_n = acceptable_nitro + unnacceptable_nitro
subtotal_nm = acceptable_nonmeth + unnacceptable_nonmeth```
You definitely have syntax errors - I have just listed one area (of a few) that you need to look at. Hint, think semi-colon.

Also, have a close look at what you have done with your ints and floating point numbers. Of course if you don't see what is wrong before your program will compile, you will see it after.

~/

10. 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!