else/if

The Question I have is:

Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64, and adds 1 to the variable seniors if age is 65 or older.

The code I input keeps marking me wrong, so I am not sure what I am entering wrong. FYI this is via myprogramminglab.


if (age < 18)
minors++;
else if ( 18 < age )
adults ++;
else if ( 65 < age)
seniors ++;
Something like
1
2
3
4
5
6
7
if (age < 18)
//
else if ( age >= 65)
//
else
//
;


Actually the else if ( 65 < age) is never reached since else if ( 18 < age ) already includes this condition.

1
2
3
4
5
6
if (age < 18)
  minors++;
else if ( age < 65)
  adults ++;
else
  seniors ++;
It worked, thanks! Gets frustrating sometimes but I love it
Topic archived. No new replies allowed.