Simple Expressions 8

Description

Using basic expressions, calculate and display values with input provided by the user.

In this exercise, we are simulating a car’s fuel tank

Requirements

  1. Add another #include line for <iomanip>. This additional line provides support for rounding and number precision.
    #include <iostream>
    #include <iomanip>
    
  2. Declare a double called capacity.
  3. Declare and initialize a double called mpg. Set this to 20.0
  4. Declare a double called remaining
  5. Declare a double called cost
  6. Add this line of code after all your variable declarations. Type it exactly as below. This line of code is used for formatting numbers with decimal places.
    cout << fixed << setprecision(1);
  7. Use cin to ask the user to enter a value for capacity. See the Sample Interaction below on what message you will display to the user
  8. This is a good point to stop and do a test compile. If you run your program at this point, nothing will be displayed yet.
  9. After your test compile, fix any errors you may have encountered. Continue below once you fix any errors you had.
  10. Ask the user to enter a value for remaining. See the Sample Interaction below on what message you will display to the user
  11. Ask the user to enter a value for cost (this is the cost of gas per gallon).
  12. Display a message (see Sample Interaction) of how much  it will cost to fill up the gas tank. Don’t forget you will only pay for how much you actually purchase to fill up the tank.
  13. Display a message showing how many miles the car will be able to go based on a full tank.

DO NOT USE

You may not use any conditional constructs such as the IF statement

Sample Interaction / Output

What is the capacity of your gas tank (gallons)? 15
How much gas do you still have in the tank? 5.0
What is the cost of gas per gallon? 3.99
To fill up your gas tank, you will pay $39.90

Once you fill up, you will be able to drive 300 miles

LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT

CATALOG ID: CPP-EXP0008

Print Requirements