The problem is the WHILE loop and the condition which is needed to end the loop. it is currently set to EOF but this does not seen to be giveing me any response.
THanks.
#include<stdio.h>
/* Exercise 3.17, Deitel & Deitel
Because of the high price of gasoline, drivers are concerned with
the mileage obtained by their automobiles. One driver has kept track
of several tankfuls of gasoline by recording miles driven and gallons
used for each tankful. Develop a C program that will input the miles
driven and gallons used for each tankful. The program should calculate
and display the miles per gallon obtained for each tankful. After
processing all input information, the program should calculate and print
the combined miles per gallon obtained for all tankfuls. */
void main()
{
float gallons, miles;
float total_gallons = 0.0, total_miles = 0.0;
float average;
/* Input the gallons used for the first tank */
printf("Enter the gallons used (-1 to end): ");
scanf("%f", &gallons);
fflush(stdin);
while (gallons != EOF)
{
/* Add gallons to running total of gallons used*/
total_gallons = total_gallons + gallons;
/* Input the miles driven for the current tank */
printf("Enter the miles driven: ");
scanf("%f", &miles);
fflush(stdin);
/* Add miles to the running total of miles driven */
total_miles = total_miles + miles;
/* Calculate and print the miles/gallon */
printf("The miles/gallon for this tank was %.2f\n\n", miles/gallons);
/* Input the gallons used for the next tank */
printf("Enter the gallons used (-1 to end): ");
scanf("%f", &gallons);
fflush(stdin);
}
/* Calculate and display the average miles/gallon */
average = total_miles / total_gallons;
printf("The overall average miles/gallon was %.2f\n", average);
}