In the Happy Valley School System, children are classified by age as follows:

less than 2, ineligible
2, toddler
3-5, early childhood
6-7, young reader
8-10, elementary
11 and 12, middle
13, impossible
14-16, high school
17-18, scholar
greater than 18, ineligible
Given an int variable age, write a switch statement that prints out the appropriate label from the above list based on age.

Respuesta :

switch(age){

// cases to output appropriate classification

case(age<2 && age>0):

cout<<"ineligible";

case(age==2):

cout<<"toddler";

case(age>=3 && age<=5):

cout<<"early childhood";

case(age==6 || age==7):

cout<<"young reader";

case(age>=8 && age<=10):

cout<<"elementary";

case(age==13):

cout<<"impossible";

case(age>=14 && age<=16):

cout<<"high school";

case(age==17 || age==18):

cout<<"scholar";

case(age>18);

cout<<"ineligible";

default:

cout<<"Invalid age";

}

Otras preguntas