The MATLAB program below is written using if-elseif-else statement. Convert it t
ID: 3833692 • Letter: T
Question
The MATLAB program below is written using if-elseif-else statement. Convert it to a case-switch statement. #This script asks the user for a type of pizza % and prints which type to order using if-else while 1 my pick = menu('Pick a pizza', 'Cheese', 'Shroom', 'Sausage', 'No Pizza'); if my pick == 1 disp('Order a cheese pizza'') elseif mypick == 2 disp('Order a mushroom pizza'') else if my pick == 3 disp('Order a sausage pizza?') else disp('No pizza for us today'') dips(*Addio!!'') break; end endExplanation / Answer
above code using switch case statement:
while 1
mypick = menu('Pick a pizza', 'Cheese', 'Shroom','Sausage','No Pizza');
switch ( mypick)
{
case 1:
disp('Order a cheese pizza!');
break;
case 2:
disp('Order a mushroom pizza!');
break;
case 3:
disp('Order a sausage pizza!');
break;
default:
disp('No pizza for us today!');
disp('Addio!!');
break;
}
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.