Question: Flow Control 1 C Description The purpose of this challenge is to use the IF statement to control program flow. This challenge simulates using a
Flow Control C
Description
The purpose of this challenge is to use the IF statement to control program flow. This challenge simulates using a credit or debit card at the gas pump.
Requirements
Declare a double variable called total
Declare a double variable called gallons
Declare a char variable called paymenttype
Declare a double variable called cost. Initialize this value to
Declare a bool variable called authorized. Initialize this value to false.
Ask the user the type of payment that will be made. Use the paymenttype variable to receive this user input.
If the user enters a it will be a credit card payment
Ask the user to enter a zipcode you will have to create a variable to store the value of the zipcode that the user enters; you decide what data type is appropriate
Write a nestedif statement and check that the value of the zipcode entered is If the zipcode entered is correct, set authorized to true.
If the user enters a it will be a debit card payment.
Ask the user to enter a PIN You will have to create a variable to store the value of the PIN that the user enters; you decide what data type is appropriate
Write a nestedif statement and check that the value of the PIN entered is If the PIN entered is correct, set authorized to true and change the value of cost to
If authorized is true, only then will you do the following:
Ask the user how many gallons are being purchased. User will enter a numeric amount. Use gallons variable to hold this amount.
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 to the total cost for debit card purchases.
Display the cost of the purchase to the user.
Add an else block after checking if authorized is true. In this section, show an appropriate message indicating an invalid PIN or ZIP code see the Sample Interaction below
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
