Question

Write a program to compute miles per gallon of a car, over a long trip. The...

Write a program to compute miles per gallon of a car, over a long trip.

The car begins the trip with a full tank, and each fuel stop along the way fills the tank again. You will not do any math, arithmetic, or computations in the main() function. All output will be displayed from the main() function.

Start the program by asking the user for the starting odometer reading. All odometer readings will be in whole miles only. The fuel tank is full.

Next, your program should ask for a series of subsequent odometer readings, along with the amount of fuel added to the tank to fill it. Fuel is measured in gallons to 3 decimal places. The car has an 18.25 gallon capacity. Validate your input to ensure that no more than 18.25 gallons is added, and that the odometer reading is larger than the previous reading. The trip is over when the user enters 0 gallons of fuel. The car will be filled at least once on the trip.

Use a void function named ComputeTankMPG to compute the miles per gallon of each tank of fuel on the trip. Do not use cout in this function.

Use a void function named ComputeTripMPG to compute the miles per gallon of the entire trip. This is computed by dividing the total trip miles by the total trip gallons. Do not use cout in this function.

All computations are to be done in the functions. Your main function should do no arithmetic operations whatsoever (comparisons such as "greater than" are not arithmetic operations, so you may use those for validation in main).

Do not use global variables.

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:
Write a program to compute miles per gallon of a car, over a long trip. The...
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
  • You are going on a long trip and want to calculate your Miles per gallon. When...

    You are going on a long trip and want to calculate your Miles per gallon. When you start your trip your odometer read 102528 miles. At the end of your trip your odometer reads 103116 miles. You started with a full tank and to return to a full tank you put in 12 gallons of gas total. What is your miles per gallon? Preview mpg

  • Compute for Miles Per Gallon in C++

    Make a program that will calculate and compute for the quotient of miles and gallons (mpg: miles per gallons). Your program should must ask the user to specify the size of the array (using dynamic array) for the following variable: miles ,gallons and mpg. Prompt the user to Initialize  the value of miles (value for miles should be 100-250) and gallons (values should be from 5-25). Use pointer galPtr for gallons, milPtr for miles and mpgPtr for mpg.  Use function...

  • A liter is 0.264179 gallons. Write a program that will read in the number of liters...

    A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon. After doing this... Modify your...

  • python code DC Final Project Implement a class Car with the following properties. A car has...

    python code DC Final Project Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. The efficiency is specified in the constructor, and the initial fuel level is 0. The following two lines are written in a File called FuelEffic.txt (you have to read these from the txt file) Miles per gallon: 20 Tank Size (in gallons): 25 Therefore, based on these...

  • The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you w...

    The assignment is to write a program in unix using C++ environment Car Instrument Simulator For this assignment you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are: • The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are – To know the car’s current amount of fuel, in gallons. – To report the car’s current amount of fuel, in gallons. – To...

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked,...

  • // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter...

    // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter your class section, and time /* The program TripCost.cpp uses pointers to calculate    the cost of a trip depending on the cost of a gallon    of gas, the number of miles, and the number of miles    per gallon a car gets. */ /* The cost of gas, the number of miles, and number of    miles per gallon is entered. */...

  • In JAVA In this assignment you will use a class Car to represent a car that travels to various de...

    In JAVA In this assignment you will use a class Car to represent a car that travels to various destinations. Your car has a fuel economy rating of 32.3 miles per gallon. The gas tank holds 19.5 gallons. Your program will need to simulate two trips: 1) BC to Yosemite Valley, and 2) BC to Washington, D.C.. For each trip you will start with a full tank of gas. The output should look as follows. Trip one: Bakersfield College to...

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

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