CS 2400 HW 1, Gas Consumption solution

$30.00

Original Work ?
Category:

Description

5/5 - (3 votes)

Objectives:

Variable declaration, simple arithmetic calculation, input, output
A car averages 22.5 miles per gallon when driven in town and 29.5 miles per gallon when driven
on the highway.

Write a program that calculates the gas consumption for a trip given the
number of miles driven in town and on the highway.

Your program should ask the user to enter
the number of miles driven in town and the number of miles driven on the highway.

The program should then calculate and output the following:

• The number of miles driven in town
• The gas consumption for town driving
• The number of miles driven on the highway
• The gas consumption for highway driving
• The total number of miles driven
• The total gas consumption
• The average miles per gallon for the whole trip

Sample User Interaction:
Enter the number of miles driven in town: 100
Enter the number of miles driven on the highway: 150
————— Gas consumption ——————-
The number of miles driven in town: 100 miles
The gas consumption for town driving: 4.44444 gallons
The number of miles driven on the highway: 150 miles
The gas consumption for highway driving: 5.08475 gallons
The total miles driven: 250 miles
The total gas consumption: 9.52919 gallons
The average mpg for the trip: 26.2352 miles/gallon

—————————————————
User input shown in red and calculated values are shown in green.

Grading:

Programs that contain syntax errors will earn zero points.

Your grade will be determine using the following criteria:
• Correctness (16 points)
o All output results are displayed as requested and have accurate values. (10
points)
o Clarity and format of the output (6 points)
• Style & Documentation (4 points).