Thanks everyone for the help, but this was the correct
answer.

I needed to do it like this......


(btw, I am using bloodshed :))

void main(void)

{


    float gallons, miles, mpg, gallonaccumulator,
milesaccumulator, overall;
    int counter;

    gallonaccumulator     = 0;
    milesaccumulator      = 0;
    
        printf("Welcome to my totally awesome milage
calculator!.");
        printf("\n\nThis program will calculate the miles per
gallon for you for three tanks of gas after you have
entered the gallons used and miles driven.\n\n");
    for (counter=1; counter <=3; counter++)
            {
                        if (counter == 1)
                            printf("Enter the number
of gallons used for tank#%i:  ", counter);
                        else
                            printf("\nEnter the number
of gallons used for tank#%i:  ", counter);
                    scanf("%f", &gallons);
                    gallonaccumulator =
gallonaccumulator + gallons;
                    fflush (stdin);
                    printf("Enter the number of miles
driven:   ");
                    scanf("%f", &miles);
                    milesaccumulator =
milesaccumulator + miles;
                    fflush (stdin);
                    mpg = miles / gallons;
                    printf("*** The miles per gallon
for this tank is %.1f\n", mpg);     
         }
     overall = milesaccumulator / gallonaccumulator;
     printf("\nYour overall average miles per gallon
for three tanks is %.1f", overall);
     printf("\n\nThank you for using my awesome
program!");

--- nobozoz <[EMAIL PROTECTED]> wrote:

> Z,
> I think this works ...
>
//-------------------------------------------------------------------------
> #include <stdio.h>
> /*Main program body*/
> void main(void)
> {
> float gallons, miles, mpg;
> int counter;
>     for (counter=1; counter <=3; counter++)
>     {
>         printf("\nEnter the number of gallons used
> for tank#%i:  ",
> counter);
>         scanf("%f", &gallons);
>         printf("Enter the number of miles driven:  
> ");
>         scanf("%f", &miles);
>         mpg = miles / gallons;
>         printf("*** The miles per gallon for this
> tank is %f \n", mpg);
>     }
>     printf("\n\r");
>     printf("Enter any number to exit ...");
>     scanf("%f", &miles);
> }
>
//-------------------------------------------------------------------------
> The big problem in the version you submitted is that
> mpg cannot be
> calculated correctly
> until BOTH gallons AND miles have been initialized.
> After gallons and miles
> have been
> entered, you want to calculate mpg and print the
> result and then repeat the
> same process
> two more times with different values for gallons or
> miles.
> 
> You don't need the "if/then" to accomplish this
> pattern.
> 
> Good luck with "c". It can be a very useful thing to
> know if you have a
> decent IDE and
> compiler. I used this:
>  http://www.bloodshed.net/devcpp.html
> 
> _jim
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf
> Of Zulfiqar Naushad
> Sent: Sunday, February 26, 2006 1:33 AM
> To: The Hardware List
> Subject: [H] C programming question
> 
> 
> I have some basic question regarding some C program
> that I have made just for fun (I am trying to teach
> myself C)
> 
> Please have a look at the program below:
> 
> If you compile it then the error will be self
> apparent, the first time it calculates the MPG it
> returns zero, the second mpg calculation is actually
> for the first one and so on :).
> 
> #include <stdio.h>
> 
> /*Main program body*/
> 
> void main(void)
> {
> float gallons, miles, mpg;
> int counter;
> for (counter=1; counter <=3; counter++)
>       {
>       mpg = miles / gallons;
>       if (counter == 1)
>          printf("Enter the number of gallons used
> for tank#%i:  ", counter);
>       else
>          printf("\nEnter the number of gallons used
> for tank#%i:  ",
> counter);
>          scanf("%f", &gallons);
>          printf("Enter the number of miles driven:  
> ");
>          scanf("%f", &miles);
>          printf("*** The miles per gallon for this
> tank is %f", mpg);
>       }
> }
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to