Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions