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 tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankful up to this point. (Use the five-step problem solving methodology)

The results should look like the following:


Enter the miles used (-1 to quit): 287

Enter gallons: 13

MPG this tankful: 22.076923

Total MPG: 22.076923

Enter the miles used (-1 to quit): 200

Enter gallons: 10 MPG this tankful: 20.000000

Total MPG: 21.173913

Enter the miles used (-1 to quit): -1

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

using namespace std;

int main() {
    int miles, gallons, totalMiles = 0, totalGallons = 0;
    while (true) {
        cout << "Enter the miles used (-1 to quit): ";
        cin >> miles;
        if (miles == -1)
            break;
        cout << "Enter gallons: ";
        cin >> gallons;
        cout << "MPG this tankful: " << miles/(double)gallons << endl;
        totalGallons += gallons;
        totalMiles += miles;
        cout << "Total MPG: " << totalMiles/(double)totalGallons << endl << endl;
    }
    return 0;
}
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
  • 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....

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

  • Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons us

    Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankful of gasoline by recording miles driven and gallons used for each tankful. Develop a C++ program that inputs the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

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

    7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script that will take as input the miles driven and gallons used (both as integers) for each tankful. The script should calculate and output HTML5 text that displays the number of miles per gallon obtained for each tankful and the combined...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • Your small remodeling business has two work vehicles. One is a small passenger car used for...

    Your small remodeling business has two work vehicles. One is a small passenger car used for job-site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car will get...

  • Your small remodeling business has two work vehicles. One is a small passenger car used for...

    Your small remodeling business has two work vehicles. One is a small passenger car used for job-site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car will get...

  • In Visual Basics - Program 2. Mileage Write a program which allows the user to enter...

    In Visual Basics - Program 2. Mileage Write a program which allows the user to enter the distance they have traveled by car in miles and the number of gallons of gasoline they used to travel the distance. Be sure to allow for decimal places for both values. Your results should show miles per gallon and kilometers per gallon. A kilometer is 0.61 miles, and this value must be stored as a constant. Your outputs must be formatted to 2...

  • 10 Your small remodeling business has two work vehicles. One is a small passenger car used for job site visits and for...

    10 Your small remodeling business has two work vehicles. One is a small passenger car used for job site visits and for other general business purposes. The other is a heavy truck used to haul equipment. The car gets 25 miles per gallon (mpg). The truck gets 10 mpg. You want to improve gas mileage to save money, and you have enough money to upgrade one vehicle. The upgrade cost will be the same for both vehicles. An upgraded car...

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