Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 1C
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 payment_type
Declare a double variable called cost. Initialize this value to 2.55
Declare a bool variable called authorized. Initialize this value to false.
Ask the user the type of payment that will be made. Use the payment_type variable to receive this user input.
If the user enters a 'c', 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 nested-if statement and check that the value of the zipcode entered is 93301. If the zipcode entered is correct, set authorized to true.
If the user enters a 'd', 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 nested-if statement and check that the value of the PIN entered is 1234. If the PIN entered is correct, set authorized to true and change the value of cost to 2.35.
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 0.35 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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

Are my points each supported by at least two subpoints?

Answered: 1 week ago