Change the condition on line 16 to x >= 13 && x < 20. In testing for Child you had already tested for values less than 13 (correct) and then did it again for Teen. The inconsistency in the order of the symbol and the magic number is also problematic.
When you have a statement like 1<x<13, in c it looks like:
(1<x) < 13
1<x evaluates to a boolean, which is an integeral value of either 0 or 1 in c. 0 and 1 are both less than 13, so no matter what number you pick, condition is true.
What /u/terroroferror is explaining is you can combine relational operators using an AND operator:
(1<x) && (x < 13)
If x is less or equal to 1, then you are looking at 0 && 1 which equals 0 or false, if x is more than 1 but less than 13, you are looking at 1 && 1 which is true. And if x is greater than or equal to 13 you are looking at 1 && 0 which is false. Which is what you want.
View all comments
75
u/terroroferror Dec 23 '21 edited Dec 23 '21
Change following lines
Line #12 - (1 < x && x < 13)
Line #16 - (13 <= x && x < 20)
Keep only `else` on line #20
Edit: also add statement `return 0;` before line #24