9.6k views
5 votes
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.

if (age < 18) {

minors = minors + 1;

} else if (age > 17 && age < 65) {

adults = adults + 1;

} else {

seniors = seniors + 1;

}

User Ezechiel
by
4.4k points

1 Answer

4 votes

Answer:

See Explanation

Step-by-step explanation:

The answer you attached to the question is correct and it does not need any additional input.

However, I'll explain each line for you

This line checks if age is less than 18

if (age < 18) {

This line increases minors by 1

minors = minors + 1;

}

This line checks if age is between 18 and 64

else if (age > 17 && age < 65) {

This line increases adult by 1

adults = adults + 1;

}

This line checks if age is greater than 18

else {

This line increases seniors by 1

seniors = seniors + 1;

}

User Tomasz Elendt
by
4.5k points