Write an if/else statement that adds 1 to minors if age is less than 18, adds 1 to adults if age is 18 through 64 and adds 1 to seniors if age is 65 or older.
Note: This code is wrtieen using "C".
if(age<18)
minors = minors+1;
else if (age>=18 && age<=64)
adults= adults+1;
else
seniors= seniors+1;
The IF condition checks for the age < 18 and if its true then it increments minors or else go to next branching
Now IF is false then it comes to else if and checks that age should be in the range between 18 and 64; The logical operator "&&" checks and returns TRUE if both conditions are met or else it executes the ELSE statement.
If above both are false, then ELSE will be executed for age greater than or equal 65 people.
Any queires comment.
Get Answers For Free
Most questions answered within 1 hours.