224k views
2 votes
Write an if/else statement that compares the variable age with 65, adds 1 to the variable seniorCitizens if age is greater than or equal to 65, and adds 1 to the variable nonSeniors otherwise show the age of seniorCitizens.

User Acharuva
by
6.0k points

1 Answer

0 votes

Answer:

Hi!

Explanation in Javascript:

int age;

int seniorCitizens = 0;

int nonSeniors = 0;

while(true) { //infinite loop, always true.

age = getAge(); // gets the age.

if (age >= 65) { // if age is greater or equal to 65 adds 1 to seniorCitizens and show the age.

o

seniorCitizens = seniorCitizens + 1;

print (age);

}

else { // otherwise adds 1 to nonSeniors.

nonSeniors = nonSeniors + 1; //

}

User Naphat Amundsen
by
5.9k points