divider

Objective

Create a console application that prompts the user to input the distance they plan to travel, their vehicle's miles per gallon (mpg), and the current price of gas per gallon. The program will then calculate and display the total amount of gas needed for the trip and the total cost.

Skills to Practice

  • icon Prompting a user for input
  • icon Converting input to the correct data type (if necessary)
  • icon Performing arithmetic calculations
  • icon Rounding decimal numbers
  • icon Formatting output
divider

Tasks

  • icon Create a new project named 1-7-fuel-calculator
  • icon Complete the following tasks:
    • icon Prompt the user to input three pieces of data:
      • icon distance
      • icon vehicle gas mileage
      • icon gas price per gallon
    • icon Use this information to calculate:
      • icon Total gallons of gas needed
      • icon Total cost for the gas
    • icon Display the results in a clear format.
divider

Sample Output

Sample Output
--- Fuel Calculator ---
How many miles are you traveling? 150 [Enter]
What is your vehicle's gas mileage (mpg)? 34 [Enter]
What is the current price of gas per gallon? $2.95 [Enter]
For your trip, you will need 4.4 gallons of gas costing $12.98 total.

Begin Challenge