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 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.

Output
Enter the gallons used (-1 to end): 16
Enter the miles driven: 220
The Miles / Gallon for this tank was 13.75
Enter the gallons used (-1 to end): 16.5
Enter the miles driven: 272
The Miles / Gallon for this tank was 16.4848
Enter the gallons used (-1 to end): -1
The overall average Miles/Gallon was 15.1385

- This bottom code is what I had, but I am having trouble inputing the second number of gallons used. The command promt just continously creates more wording and does not allow for an input. What could be the fix or a code that works? Also it would be nice if there was some explanation to each part of the code.

//Header file section
#include<iostream>
using namespace std;
void main()
{
   float miles, gallons, MPG, totMiles = 0, totGallons = 0;
   int i = 1;
   //inputting miles
   cout << "Enter mileage for trip:#" << i << " :";
   cin >> miles;
   //inputting gallons
   cout << "Enter galllons for trip:#" << i << " :";
   cin >> gallons;
   do
   {
       MPG = miles / gallons;
       totMiles += miles;
       totGallons += gallons;
       cout << "MPG for trip " << i << " :" << MPG << end1;
       cout << " MPG for all trips so far is : "
           << totalMiles / totGallons << end1;
       i++;
       //inputting miles
       cout << "Enter mileage for trip:#" << i << " :";
       cin >> miles;
       if (miles == -1)
           break;
       //inputting gallons
       cout << "Enter gallons for trip:#" << i << " :";
       cin >> gallons;

   } while (miles != -1);
   cout << "Thanks for using our MPG program!" << end1;
}//end main

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
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.

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