In: Computer Science
Write the Pseudocode for the following programming problem.
Write a program that will calculate a tip based on the meal price and a 6% tax on a meal price. The user will enter the meal price and the program will calculate tip, tax, and the total. The total is the meal price plus the tip plus the tax. Your program will then display the values of tip, tax, and total.
The tip amounts based on the mean price are as follows:
Meal Price Range |
Tip Percent |
.01 to 5.99 |
10% |
6 to 12.00 |
13% |
12.01 to 17.00 |
16% |
17.01 to 25.00 |
19% |
25.01 and more |
22% |
The Pseudocode
TYPE PSEUDOCODE HERE
The Python Code for Reference
#the main function
def main():
print 'Welcome to the tip and tax calculator program'
print #prints a blank line
mealprice = input_meal()
tip = calc_tip(mealprice)
tax = calc_tax(mealprice)
total = calc_total(mealprice, tip, tax)
print_info(mealprice, tip, tax, total)
#this function will input meal price
def input_meal():
mealprice = input('Enter the meal price $')
mealprice = float(mealprice)
return mealprice
#this function will calculate tip at 20%
def calc_tip(mealprice):
if mealprice >= .01 and mealprice <= 5.99:
tip = mealprice * .10
elif mealprice >= 6 and mealprice <=12:
tip = mealprice * .13
elif mealprice >=12.01 and mealprice <=17:
tip = mealprice * .16
elif mealprice >= 17.01 and mealprice <=25:
tip = mealprice * .19
else:
tip = mealprice * .22
return tip
#this function will calculate tax at 6%
def calc_tax(mealprice):
tax = mealprice * .06
return tax
#this function will calculate tip, tax, and the total cost
def calc_total(mealprice, tip, tax):
total = mealprice + tip + tax
return total
#this function will print tip, tax, the mealprice, and the total
def print_info(mealprice, tip, tax, total):
print 'The meal price is $', mealprice
print 'The tip is $', tip
print 'The tax is $', tax
print 'The total is $', total
#calls main
main()
Here is the pseudo code for this code:
if the answer helped you please upvote and if you have any doubts please comment i will surely help.
Pseudocode:
Step 1: Take the price of the meal as input from the user and store it in a variable called "mealPrice".
Step 2: Calculate the tip, for the mealPrice and store it in a variable "tip"
Step 3: Calculate tip using the following conditions:
if mealprice>=.01 and
mealprice<=5.99:
tip = mealprice * .10
else if the mealprice>=6 and mealprice<=12:
tip = mealprice * .13
elif mealprice >=12.01 and mealprice <=17:
tip = mealprice * .16
elif mealprice >= 17.01 and mealprice <=25:
tip = mealprice * .19
else:
tip = mealprice * .22
Step 4: Calculate the tax for the price and store it in a variable called "tax"
tax = 0.06 * mealPrice
Step 5: Calculate the total cost
total = mealprice + tip + tax
Step 6: Print all the infromation of the user.