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

 Réponse acceptée

Walter Roberson
Walter Roberson le 30 Avr 2023
Modifié(e) : Walter Roberson le 30 Avr 2023
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 commentaires

Amanj
Amanj le 30 Avr 2023
Thank you very much 🙏🌸🤍🌸
Amanj
Amanj le 30 Avr 2023
I appreciate that Your life is full of joy and light🙏🤍🙏

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by