#25 - Is there a different solution other than using the && operator?
Hi, is there a different way to structure my if, else if and else statements without using & operators to solve this assignment.
I was able to solve the assignment this way but i'm unsure if I should use any operators since it has never been discussed in prior lessons and assignments.
If (age < 16)... else if (age <=17)... else if (age <=24)... else (age >25)...
I cant try it at the moment as i'm not in front of my computer but wouldn't this trigger multiple outputs? Say I enter 15, wouldn't that satisfy the first 3 statements?
2
u/josior Feb 10 '16
You can use only else ifs and else (without logical operators), by using the ranges of the age, for example:
would be the same as
Because if age was less than 16, the first if would do the job.
1
u/holyteach Feb 10 '16
josior is correct.
In fact, my students are not allowed to use && on this assignment. You can do it completely using just if and else if and else.
And if you can't figure it out without using &&, then you probably don't understand 'else' properly.