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

 Accepted Answer

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 Comments

Thank you very much 🙏🌸🤍🌸
I appreciate that Your life is full of joy and light🙏🤍🙏

Sign in to comment.

More Answers (0)

Asked:

on 30 Apr 2023

Commented:

on 30 Apr 2023

Community Treasure Hunt

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

Start Hunting!