Description
The purpose of this challenge is to use the IF statement to control program flow. This challenge simulates a credit card machine.
Requirements
- Declare a double variable called total
- Declare a double variable called gallons
- Declare a char variable called payment_type
- Declare a double variable called cost. Initialize this value to 2.55
- Ask the user how many gallons are being purchased. User will enter a numeric amount. Use gallons variable to hold this amount.
- Ask the user the type of payment that will be made. If the user enters a ‘c’, it will be a credit card payment. If the user enters a ‘d‘, it will be a debit card payment. Use the payment_type variable to receive this user input.
- If the payment_type is debit card, change the value of cost to 2.35.
- Calculate the appropriate total of the purchase depending on the payment type. Use the total variable to calculate the total amount. Additionally, you will need to add 0.35 to the total cost for debit card purchases.
- Display the cost of the purchase to the user.
Hints
- Include the <iomanip> header file. This will allow you to use various options to format your output
- It’s good practice to initialize variables to default values that make sense (for example, set gallons to 0.00)
- Include the code below before any other cout lines. The setprecision(x) will display your decimal output with x decimal places.
cout << fixed << setprecision(2);
Sample Interaction / Output
-- Welcome to GAS CLUB -- How many gallons purchased? 10 Are you paying with credit or debit (c/d)? d Gallon cost: $2.35 Thank you for your purchase of 10 gallons. Please pay $23.85. All taxes are included DRIVE SAFE - DON'T TEXT AND DRIVE
RUN IT AGAIN:
-- Welcome to GAS CLUB -- How many gallons purchased? 22 Are you paying with credit or debit (c/d)? c Gallon cost: $2.55 Thank you for your purchase of 22 gallons. Please pay $56.10. All taxes are included DRIVE SAFE - DON'T TEXT AND DRIVE
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-FLOW0001B
Print Requirements