Question
matlab only
Question 4 A restaurant sells five different desserts whose prices are shown below in the following table: Dessert number Uni
0 0
Add a comment Improve this question Transcribed image text
Answer #1

clear
clc

%displaying menu
fprintf('MENU: ')
fprintf('\nDessert number\tUnit Price')
fprintf('\n1\t\t\t\t$ 3.98')
fprintf('\n2\t\t\t\t$ 2.55')
fprintf('\n3\t\t\t\t$ 6.90')
fprintf('\n4\t\t\t\t$ 9.85')
fprintf('\n5\t\t\t\t$ 12.50')

more = true; % to allow a series of pairs to be entered
overallTotalPrice = 0;

while more
dessertNumber = input('\n\nDessert Number: ');   
  
switch dessertNumber
case 1
unitPrice = 3.98;
case 2
unitPrice = 2.55;
case 3
unitPrice = 6.90;
case 4
unitPrice = 9.85;
case 5
unitPrice = 12.50;
otherwise
error('unknown menu option')
end

quantitySold = input('Quantity Sold: ');

%capture quantity<0
if quantitySold<1
error('quantity must be atleast 1')
end


totalPrice = quantitySold*unitPrice; %for the current Dessert #

%computing overall total price cumulatively
overallTotalPrice = overallTotalPrice+totalPrice;

more = input('enter 0 to quit, or 1 to get more: ');%exiting program
end

%diaplying final total price when the customer quits
fprintf(['Total Price: $ ' num2str(overallTotalPrice) '\n\n'])


MENU: Dessert number Unit Price $ 3.98 $ 2.55 S 6.90 $ 9.85 s 12.50 Dessert Number 3 Quantity Sold: 12 enter 0 to quit, or 1

-----------------------------------------------------------------------------------

MENU: Dessert number Unit Price 1 S 3.98 $ 2.55 S 6.90 $9.85 S 12.50 Dessert Number 5 Quantity Sold: 3 enter 0 to quit, or l

COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,

IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~

Add a comment
Know the answer?
Add Answer to:
matlab only Question 4 A restaurant sells five different desserts whose prices are shown below in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A mail order house sells five different products whose retail prices are: product 1: $2.98 product...

    A mail order house sells five different products whose retail prices are: product 1: $2.98 product 2: $4.50 product 3: $9.98 product 4: $4.49 product 5: $6.87. Write a program that reads a series of pairs of numbers as follows: a) product number b) quantity sold Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to...

  • This is in C. 4.19 (Calculating Sales) An online retailer sells five different products whose retail...

    This is in C. 4.19 (Calculating Sales) An online retailer sells five different products whose retail prices are shown in the following table: Product number Retail price $ 2.98 $ 4.50 $9.98 $ 4.49 $6.87 Write a program that reads a series of pairs of numbers as follows: a) Product number b) Quantity sold for one day Your program should use a switch statement to help determine the retail price for each product. Your program should calculate and display the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT