this is the question :

Write C++ a program that reads a person's age in years and print his/her age group. See the table below.
Age------------Group name

1 year---------Childhood
2-3 years------Infancy
4-5 years------Preschool-Age
6–12 years-----School-Age
13–17 years----Adolescence
18–29 years----Young-Adulthood
30–39 years----Thirties
40–64 years----Middle-Age
56–48 years----Aged
85 years ------Very-Old

You HAVE to using switch statement.

and the answer in the first comment.

\\this is the answer:



   #include <iostream>
    using namespace std;
    int main()
    {

  int age;
        cout << "How old is the person? ";
        cin >> age;
        switch (age)
        {
   case 1:
            cout << "childhood";
            break;

   case 2: case 3:
            cout << "infancy";
            break;

   case 4 : case 5 :
            cout<<" years Preschool-Age";
            break;

   case 6: case 7 : case 8: case 9 : case 10: case 11 : case 12:
            cout<<" School-Age";
            break;

  case 13: case 14 : case 15 : case 16 : case 17 :
            cout <<" Adolescence";
            break;

  case 18:case 19:case 20 :case 21:case 22:case 23:case  24:case 25:case 26:       case 27:    case 28:
            cout <<" Young-Adulthood ";
            break;


           //wanna easier way .. instead of wirte case case case.
           //special thanks to nutster

  }

   return 0;
    }

Edited 3 Years Ago by saja.omarii.7

This article has been dead for over six months. Start a new discussion instead.