/* Exercise 3.17 Solution */ #include void main () { float gallons, miles, totalGallons = 0.0; float totalMiles = 0.0, totalAverage; printf ("Enter the gallons used (-1 to end): "); scanf ("%f", &gallons); while (gallons != -1.0) { totalGallons += gallons; printf ("Enter the miles 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); }