I wanna write same program by using switch , but how ?

I wanna write same program by using switch , but how ?:
x=input("inter your age :");
if x>=13 && x<18
disp("person is teenager")
disp("not eligible for voating")
else
disp("person is not teenager")
if x>=18
disp("eligible for voating ")
else
disp("not eligible for voating")
end
end

 採用された回答

Walter Roberson
Walter Roberson 2023 年 4 月 30 日
編集済み: Walter Roberson 2023 年 4 月 30 日

1 投票

x = input("inter your age :");
switch(true)
case x>=13 && x<18
disp("person is teenager")
disp("not eligible for voating")
case x > 18
disp("person is not teenager")
disp("eligible for voting");
otherwise
disp("person is not teenager");
disp("not eligible for vating")
end
or
x = input("inter your age :");
switch x>=13 && x<18
case true
disp("person is teenager")
disp("not eligible for voating")
otherwise
disp("person is not teenager")
switch x>=18
case true
disp("eligible for voating ")
otherwise
disp("not eligible for voating")
end
end
In the special case that your input was certain to be a non-negative integer (which is not the situation now -- users can enter negatives or fractions or vectors)
switch x
case 0:12
disp("person is not teenager")
disp("not eligible for voating")
case 13:18
disp("person is teenager")
disp("not eligible for voating")
otherwise
disp("person is not teenager");
disp("eligible for vating")
end

2 件のコメント

Amanj
Amanj 2023 年 4 月 30 日
Thank you very much 🙏🌸🤍🌸
Amanj
Amanj 2023 年 4 月 30 日
I appreciate that Your life is full of joy and light🙏🤍🙏

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

その他の回答 (0 件)

タグ

質問済み:

2023 年 4 月 30 日

コメント済み:

2023 年 4 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by