{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

C- Computer Questions- SolutionsExam 2

C- Computer Questions- SolutionsExam 2 - Computer Question...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Question 1: Write Matlab code that performs the basic tasks of a cashier at White Castle. First, use fprintf to randomly display either “Good morning”, “Good afternoon”, or “Good day”, each with equal probability. Now, display a menu asking the user what she’d like to eat: Cheeseburger $0.69 Chicken Rings $1.99 Mozzarella Sticks $2.09 Sweet Tea $1.50 Include a fifth menu option, “Let’s Eat” Each time a user clicks on a menu item, add that cost to the total (which starts at $0.00), and then display the menu again. Once the user clicks on “Let’s Eat”, stop displaying the menu, but use fprintf to display the final total (to two decimal places). Use switch/case rather than if statements in your answer. c = { 'morning' 'afternoon' 'day' }; fprintf( 'Good %s\n' ,c{ceil(3*rand(1))}) total=0; while (1) wc = menu( 'Choose your food:' , 'Cheeseburger' , 'Chicken Rings' , 'Mozzarella Sticks' , 'Sweet Tea' , 'Let''s Eat' ); switch wc case 1 total=total+0.69; case 2 total=total+1.99; case 3 total=total+2.09; case 4 total=total+1.50; case 5 break end end fprintf( 'The final total is %.2f\n' ,total) -3 if they mess up fprintf, or have a small syntax error or two -3 if they can’t get the “Good afternoon” stuff working right -4 Some sort of logic flaw, but understand all statements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}