Answered step by step
Verified Expert Solution
Question
1 Approved Answer
To create a program that calculates the cost and change for services using if - statements. Objectives To gain proficiency with the following: Nested if
To create a program that calculates the cost and change for services using ifstatements.
Objectives
To gain proficiency with the following:
Nested ifstatements
Multibranch ifstatements
Incremental development
Description
For this program, you should prompt the user for an automobile service and how much they paid, and then calculate how much change the user should receive. So if you imagine standing at the counter, you ask them what service they would like, and then you collect their payment. You would then check how much they paid against the cost of the service they requested. If they did not pay enough, you would tell that to the customer. If a service is requested that is not provided, this would also be said to the customer. If the service is offered and the customer paid enough, then you would let them know how much change they will receive for that service.
The list of possible services is as follows with their costs:
oil change: $
tire rotation: $
car wash: $
Things to think about is what happens if they select a service not from that list? What happens if they pay too little? What happens if they pay too much? These are all the things you should think about before ever starting to type any code.
If the user selects a service not shown in the list, you should display an appropriate error message. Also, if they dont pay enough, an error message should be displayed. If they pay too much, you need to give them change.
For this program, well start with the following pseudocode:
Get service type from customer
Print service type message
Get amount paid from customer
Print amount paid message
Check Service Type
If service type is oil change:
set cost to
calculate change from amount paid minus cost
if change is equal to or greater than :
a print cost message
b print change from amount paid message.
else the cost is less than :
a print error message for insufficient funds for oil change.
Else if service type is tire rotation:
Set cost to
Repeat steps through in oil change using tire rotation cost instead.
Else if service type is car wash:
Set cost to
Repeat steps through in oil change using car wash cost instead.
Otherwise service type is invalid:
Print error message for not recognized service.
Your input prompt for the auto service should be as follows:
Enter desired auto service:
with the following message printed out with servicechoice being the service from input:
You entered: servicechoice
Your input prompt for how much the user is paying should be as follows:
How much are you paying?
with the following message printed out with paidamount being the amount paid from input:
You have paid: $ paidamount
Note: Both input prompts should end with a space and a newline character.
Each cost message will be in the following format with service being the specific auto service and the service cost being that services cost:
Cost of service: $ servicecost
Each change from amount paid message will be in the following format with change being the difference between the amount paid and the services cost and paidamount being the amount paid:
You are getting $ change change back from your $ paidamount
The error message for insufficient amount paid for a service is as follows with service choice being the auto service:
Error: Your paid amount is not sufficient for the servicechoice service
The error message for an invalid service request is as follows:
Error: Requested service is not recognized
Example Runs:
Enter desired auto service:
oil change
You entered: oil change
How much are you paying?
You have paid: $
Cost of oil change: $
You are getting $ change back from your $
Enter desired auto service:
tire change
You entered: tire change
How much are you paying?
You have paid: $
Error: Requested service is not recognized
Enter desired auto service:
car wash
You entered: car wash
How much are you paying?
You have paid: $
Error: Your paid amount is not sufficient for the car wash service
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started