Modify the areaMenu script to use the listdlg function instead of printing a menu. By using switch statement and adding two more option

5 ビュー (過去 30 日間)
Modify the areaMenu script to use the listdlg function instead of printing a menu.
areaMenu.m
This is the version that I modified by using the listing funciton.;
How can I solve this question by using switch statement and how I include 2 additional options 4.trapezoid 5. Sector
________________________________________________________________________________
% Prints a menu and calculates area of user's choice
sh = listdlg('SelectionMode', 'Single',...
'PromptString', 'Menu',...
'ListString', {'Cylinder', 'Circle', 'Rectangle'});
if sh == 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)
elseif sh == 2
rad = input('Enter the radius of the circle: ');
fprintf('The area is %.2f\n', pi*rad*rad)
elseif sh == 3
len = input('Enter the length: ');
wid = input('Enter the width: ');
fprintf('The area is %.2f\n', len*wid)
else
disp('Error! Not a valid choice.')
end
  3 件のコメント
Ceren Akcam
Ceren Akcam 2021 年 12 月 24 日
編集済み: Ceren Akcam 2021 年 12 月 24 日
Sorry, I thought that I added the script. I updated my question.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 12 月 24 日
if variable == value1
code1
elseif variable == value2
code2
else
error message
end
can be replaced by
switch variable
value1: code1
value2: code2
otherwise: error message
end
  2 件のコメント
Ceren Akcam
Ceren Akcam 2021 年 12 月 24 日
Thank you but what will be the code for trapezoid and Sector ?
Walter Roberson
Walter Roberson 2021 年 12 月 25 日
I do not know; your code disappeared so I do not know what I am answering any more.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by