Question

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tanks of gasoline by recording miles driven and gallons used for each tank. Develop a program using a while loop that will input the miles driven and the gallons used for each tank. The program should calculate and display the miles per gallon obtained for each tank. After processing all input information, the program should calculate and print the overall miles per gallon obtained for all tanks.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
   double total = 0, count = 0, miles_driven, gallons, miles_per_gallon;
   while(1) {
      printf("Enter number of miles driven(-1 to exit): ");
      scanf("%lf", &miles_driven);
      if(miles_driven < 0) {
         break;
      }
      printf("Enter gallons used for tank: ");
      scanf("%lf", &gallons);
      miles_per_gallon = miles_driven / gallons;
      printf("Miles per gallon is %lf\n\n", miles_per_gallon);
      total += miles_per_gallon;
      count += 1;
   }
   printf("\nOverall miles per gallon is %lf\n", total/count);
   return 0;
}

Enter number of miles driven -1 to exit): 100 nter gallons used for tank: 10 Miles per gallon is 10.000000 Enter number of mi

Add a comment
Know the answer?
Add Answer to:
Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT