CS 200 - Lab 6

MPG Calculator

The purpose of this lab is to write a program to calculate a car's fuel economy based on the number of miles driven and the number of gallons of fuel used.

Getting Started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download lab6.zip.  Import it into Visual Studio (File->Import...).

Add your code to the source file called MilesPerGallon.c.

Your Task

Your task is to write a program that will prompt the user for two quantities.  First, the number of miles driven.  Second, the number of gallons of fuel used.

After reading these two quantities into variables, you should compute the fuel economy in miles per gallon.  Your program should display one digit to the right of the decimal point.

Here is an example run of the program.  User input is shown in bold red.

Miles driven: 400
Gallons of fuel used: 14.7
Fuel economy was 27.2 miles per gallon


The number of miles driven an number of gallons of fuel used are not necessarily whole numbers.  Your program should handle fractional values.

The fuel economy will not necessarily be a whole number.

In Visual Studio, press "Control-F5" to compile and run your program.