Help needed Please

This is a discussion on Help needed Please within the C Programming forums, part of the General Programming Boards category; ==> this is my pesudocode code for an assignment. i stayed up all last nit with minimal success trying to ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    Talking Help needed Please

    ==> 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
    read 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
    read distance from source

    if( distance > 80000 )

    if( gas_amount_pkm > 2.63 )
    display message(Carbon Monoxide emissions exceeds level of 2.63)
    Add one to Unaccept_Carmonoxide

    else if (gas_amount_pkm < 2.63 )
    display message(Carbon Monoxide emissions are acceptable)
    Add one to Accept_Carmonoxide

    if( distance < 80000 )

    if (gas_amount_pkm > 2.13 )
    display message(Carbon Monoxide emissions exceeds level of 2.13)
    Add one to Unaccept_Carmonoxide

    else if (gas_amount_pkm < 2.13 )
    display message(Carbon Monoxide emissions are acceptable)
    Add one to Accept_Carmonoxide

    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
    read distance from source

    if( distance > 80000 )

    if(gas_amount_pkm > 0.24 )
    display message(Hydrocarbon emissions exceeds level of 0.24)
    Add one to Unaccept_Hydrocarbon

    else if (gas_amount_pkm < 0.24 )
    display message(Hydrocarbon emissions are acceptable)
    Add one to Accept_Hydrocarbon

    if( distance < 80000 )

    if(gas_amount_pkm > 0.19 )
    display message(Hydrocarbon emissions exceeds level of 0.19)
    Add one to Unaccept_Hydrocarbon

    else if (gas_amount_pkm < 0.19 )
    display message(Hydrocarbon emissions are acceptable)
    Add one to Accept_Hydrocarbon

    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
    read distance from source

    if( distance > 80000 )

    if(gas_amount_pkm > 0.31 )
    display message(Nitrogen oxide emissions exceeds level of 0.31)
    Add one to Unaccept_Nitrogen

    else if (gas_amount_pkm < 0.31 )
    display message(Nitrogen oxide emissions are acceptable)
    Add one to Accept_Nitrogen

    if( distance < 80000 )

    if(gas_amount_pkm > 0.25 )
    display message(Nitrogen oxide emissions exceeds level of 0.25)
    Add one to Unaccept_Nitrogen

    else if (gas_amount_pkm < 0.25 )
    display message(Nitrogen oxide emissions are acceptable)
    Add one to Accept_Nitrogen

    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
    read distance from source

    if( distance > 80000 )

    if(gas_amount_pkm > 0.19 )
    display message(Non_methane emissions exceeds level of 0.19)
    Add one to Unaccept_Non_methane
    else if (gas_amount_pkm < 0.19 )
    display message(Non_methane emissions are acceptable)
    Add one to Accept_Non_methane

    if( distance < 80000 )

    if(gas_amount_pkm > 0.16 )
    display message(Non_methane emissions exceeds level of 0.16)
    Add one to Unaccept_Non_methane

    else if (gas_amount_pkm < 0.16 )
    display message(Nonmethane emissions are acceptable)
    Add one to Accept_Non_methane

    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. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    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.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    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. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    13

    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

    Printf please enter pollutant number

    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

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Stick to one thread please.
    My best code is written with the delete key.

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    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.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Threads joined
    Spam deleted
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    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. #9
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    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.

    ~/
    Last edited by kermit; 03-18-2004 at 04:30 AM.

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    13
    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21