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일
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

Thank you very much 🙏🌸🤍🌸
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