Q:

Modify the areaMenu script to use a switch statement to decide which area to calculate

0

Modify the areaMenu script to use a switch statement to decide which area to calculate.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

areaMenuSwitch.m

% Prints a menu and calculates area of user's choice

disp('Menu')

disp('1. Cylinder')

disp('2. Circle')

disp('3. Rectangle')

sh = input('Please choose one: ');

switch sh

 case 1 

 rad = input('Enter the radius of the cylinder: ');

 ht = input('Enter the height of the cylinder: ');

 fprintf('The surface area is %.2f\n', 2*pi*rad*ht) 

 case 2

 rad = input('Enter the radius of the circle: ');

 fprintf('The area is %.2f\n', pi*rad*rad)

 case 3

 len = input('Enter the length: ');

 wid = input('Enter the width: ');

 fprintf('The area is %.2f\n', len*wid)

 otherwise

 disp('Error! Not a valid choice.')

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now