I only get a result of "1.00" for each mileage calc and also for the overall average, regardless of numbers input. Can anyone see where the problem(s) is in my program below? Thanks in advance!
#include <stdio.h>
void main(void )
{
/* Variable Declarations */
/* ---------------------- */
float number_gallons;
float number_miles;
float overall;
float total_gallons = 0; //accumulators
float total_miles = 0;
float result;
int i; //counter
printf ("This program will calculate the miles per gallon for 3 tanks of gas.\n \n");
for (i = 1; i <=3; i=i + 1)
{
printf ("Enter the number of gallons used for tank #%i: ", i);
scanf ("%.2f", &number_gallons);
fflush (stdin);
printf ("Enter the number of miles driven: ");
scanf ("%.2f", &number_miles);
fflush (stdin);
result = number_miles/number_gallons;
printf ("***The miles per gallon for this tank is %.2f \n \n", result);
total_gallons = total_gallons + number_gallons;
total_miles = total_miles + number_miles;
} // end for loop
/* Calculate overall average miles per gallon */
overall = total_miles / total_gallons;
printf ("Your overall average miles per gallon for three tanks is %.2f \n \n", overall);
} // end main