+ 1
Why isn't the switch statement working?
5 Answers
+ 2
Because that's not how switch statements work. They are only used to compare a value to another one. For this, you should use a chained if-else statement
+ 1
what was meant was, you declared 'x', then used 'age' as the operator. Switch case statements tests for specific values, when u you know exactly the elements in the array of numbers that can be entered by a user
https://code.sololearn.com/cWXbP80x9oj4/?ref=app
something like this
+ 1
there is, if that's what you'd want to do, the top comment answered that.
0
Yes, of course Anon you can modify.
Also using 'age' everywhere instead of 'x' doesn't work. I ran the code that way too.
0
That works......but I wanted to create a code which will give an output for a range of ages typed.......there isn't any restriction on using logical operators in switch statements, right??