# CS 2400 HW 1, Gas Consumption solved

\$35.00

## Description

5/5 - (1 vote)

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.