Question: You will be creating a program that calculates a fleet's car and truck miles per gallon. Create a program that continually asks for a command,

You will be creating a program that calculates a fleet's car and truck miles per gallon.

Create a program that continually asks for a command, which will be "car", "truck", or "done". If the user does not specify one of these commands, output "Unknown command."

If the user types "done", calculate the average miles per gallon of all of the given cars and calculate the average miles per gallon of all of the given trucks. If the user did not provide any cars, output "Fleet has no cars." If the user did not provide any trucks, output "Fleet has no trucks." Otherwise, output "Average car MPG = " and "Average truck MPG = ".If the user types "truck" or "car", then ask the user for the number of miles and number of gallons of fuel used on either the truck or car. This will be a running total. You will need to store the total number of miles, total number of gallons, and total number of cars and trucks.You must also make a check to ensure the user gives you proper input. If improper input was given, keep asking the user to give you legitimate values until they comply (see examples below).

./lab4 Enter command: car Enter car's miles: 255 Enter car's gallons: 13 Enter command: car Enter car's miles: 715 Enter car's gallons: 33 Enter command: truck Enter truck's miles: 477 Enter truck's gallons: 22 Enter command: done Average car MPG = 21.087 Average truck MPG = 21.6818

1. car, truck, and done are the only commands accepted. Car is not a valid command, and neither is Truck.

2. You do not need to strip off the end of a valid number, such as 18.2dz. The extraction operator will extract 18.2 and leave dz in the stream, which will need to be ignored later since it will try to match the next command.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!