← Back
Code Challenge 1.10 - Fuel Calculator
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
- Prompting a user for input
- Converting input to the correct data type (if necessary)
- Performing arithmetic calculations
- Rounding decimal numbers
- Formatting output
Challenge Tasks
- Create a console project named Challenge 1-10.
- Prompt the user to input three pieces of data: distance, vehicle gas mileage, and gas price per gallon.
- Use this information to calculate:
- The total gallons of gas needed.
- The total cost for the gas.
- Display the results in a clear format.
Sample Output
--- Fuel Calculator ---
How many miles are you traveling? 150
What is your vehicle's gas mileage (mpg)? 34
What is the current price of gas per gallon? $2.95
For your trip, you will need 4.4 gallons of gas costing $12.98 total.