Modify the areaMenu script to use a switch statement to decide which area to calculate
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:4| Question number:26.4
All Answers
total answers (1)
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