CMSC201
Programming Project One
Gas Mileage
Out: Tuesday 2/18/97
Due: Midnight Tuesday 3/4/97
|
The Objective
The objective of this assignment is to make sure that you have learned enough
about C and the UNIX system to write a simple program, compile it, run it and
turn it in using submit. In particular, it will give you some practice using
several data types and will require the use of a while loop that terminates
on the input of a sentinel value.
The Explanation
This program will allow you to compare brands of gasoline. Some drivers
find that a particular brand of gasoline will allow them to get better gas
mileage than other brands. The user will be allowed to test as many brands
as he/she sees fit. The program must calculate and display the gas mileage
for each brand of gasoline individually. After the testing is complete, the
average miles per gallon across all tests is to be reported.
Gas mileage is simply the number of miles traveled divided by the gallons of
gas burned. All cars have an odometer which is a meter that shows the number
of miles the car has been driven. The odometer on the car used for this test
tells only the number of whole miles driven, an integer. Gas pumps have a
guage that tells how much gas was sold in gallons to the nearest 100th of a
gallon.
To begin the testing, you must fill the tank with gasoline, get the odometer
reading, and record the brand you're using. On subsequent fills, you'll also
need to know how many gallons of gas it takes to fill the tank. (Hint: The
amount of gas it takes to fill the tank is equivalent to the amount of gas
burned since the last fill-up.) The user is to end the testing by entering
an odometer reading of 0. At this point a report should be generated that
shows the total number of miles travelled, the total amount of gas burned,
and the average gas mileage of the car.
Your program must generate all of the same information as shown in the
sample run. You do not need to match the output exactly, however the gas
mileage should always be shown to two decimal places. You may also use the
data shown here to test your program for accuracy. Note: The gas mileage on
the last fill cannot be calculated, but a message should be displayed to that
effect.
The Sample Run
umbc9[1]% a.out
Please enter the initial odometer reading: 35000
Please enter the Gasoline Brand: Performance++
Next Fill:
Please enter the new odometer reading: 35375
*** Miles travelled: 375
Please enter the number of gallons: 13.00
*** Miles per gallon using Performance++ is 28.85 mpg.
Please enter the new Gasoline Brand: NoFumes
Next Fill:
Please enter the new odometer reading: 35725
*** Miles travelled: 350
Please enter the number of gallons: 12.82
*** Miles per gallon using NoFumes is 27.30 mpg.
Please enter the new Gasoline Brand: EconoDrive
Next Fill:
Please enter the new odometer reading: 35935
*** Miles travelled: 210
Please enter the number of gallons: 8.37
*** Miles per gallon using EconoDrive is 25.09 mpg.
Please enter the new Gasoline Brand: BrandX
Next Fill:
Please enter the new odometer reading: 36235
*** Miles travelled: 300
Please enter the number of gallons: 11.36
*** Miles per gallon using BrandX is 26.41 mpg.
Please enter the new Gasoline Brand: TurboClean
Next Fill:
Please enter the new odometer reading: 0
*** Mileage using TurboClean not calculated.
*** Total mileage for test: 1235
*** Total gallons consumed: 45.55
*** Average Miles Per Gallon: 27.11
umbc9[2]%
Submitting the Program
To submit the file you should use the command:
submit cs201 proj1 proj1.c
You can check your submission by using the command:
submitls cs201 proj1