This seems to be a popular assignment. I'm most finished with it but I need to average the three readings and I'm not able to get the math to roll the right way.
Was hoping to get some help on how to finish this thing up.
Code:
#include <stdio.h>
int main (void)
{
int input;
int x;
int counter = 0;
float gallonsUsed, milesDriven, mpg;
float total = 0;
float avgMPG = 0;
printf ("Welcome to the mileage calculator.\n");
printf ("\n");
printf ("This 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");
printf ("\n");
for ( x = 0; x < 3; x++ )
{
total = total + mpg;
counter = counter + 1;
printf ("Enter the number of gallons used for tank #%d: ", x + 1);
scanf ("%f", &gallonsUsed);
printf ("Enter the number of miles driven: ");
scanf ("%f", &milesDriven);
mpg = milesDriven / gallonsUsed; //mpg
printf ("*** The miles per gallon for this tank is %.1f\n", mpg);
getchar( );
printf ("\n");
}
avgMPG = (float) total / counter;
printf ("Your overall average miles per gallon for three tanks is %.1f\n", avgMPG);
printf ("\n");
printf ("Thank you for using the program. Goodbye.");
printf ("\n");
}