C program to calculate average miles/gallon from multiple entry.

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. De- velop a 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. Here is a sample input/output dialog:

Enter the gallons used (-1 to end) : 12.8
Enter the miles driven: 287 
The miles per gallon for this tank was 22.421875

Enter the gallons used (-1 to end) : 10.3
Enter the miles driven: 200 
The miles per gallon for this tank was 19.417476

Enter the gallons used (-1 to end) : 5
Enter the miles driven: 120 
The miles per gallon for this tank was 24.000000

Enter the gallons used (-1 to end) : -1

The overall average miles/gallon was 21.601423

#include <stdio.h>
int main (void){
float gallons;
float miles;
float totalGallons = 0.0;
float totalMiles = 0.0;
float totalAverage;

printf(“Enter the gallons used (-1 to end): “);
scanf(“%f”, &gallons);

while (gallons != -1.0) {
totalGallons += gallons;
 
printf(“Enter the miled driven: “);
scanf(“%f”, &miles);
totalMiles += miles;

printf(“The Miles / gallon for this tank was %f\n\n”, miles / gallons);

printf(“Enter the gallons used (-1 to end): “);
scanf(“%f”, &gallons);
}

totalAverage = totalMiles/totalGallons;
printf(“\nThe overall average miles/gallon was %f\n”, totalAverage);

return 0;
}
P