9th Jul 2019, 6:47 PM
Hardik
Hardik - avatar
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
9th Jul 2019, 6:49 PM
Airree
Airree - avatar
+ 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
9th Jul 2019, 7:28 PM
Anon
Anon - avatar
+ 1
there is, if that's what you'd want to do, the top comment answered that.
9th Jul 2019, 7:37 PM
Anon
Anon - avatar
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.
9th Jul 2019, 7:25 PM
Hardik
Hardik - avatar
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??
9th Jul 2019, 7:34 PM
Hardik
Hardik - avatar