By 26/03/2014 12 Comments

Exercise # 03 Decision Making Statements in C++

Q: Write a program which gives the following output

Enter age>>

And prints the following:

If Age is greater than 45 then prints the message “You are old stay at home and wait for call”

If Age is greater than 30 and less than 45 then prints “Hey! man enjoy your life with your kids”

If Age is greater than 20 and less than 30 then prints “Cool! have a search for your best suit” 

If Age is greater than 10 and less than 20 then prints “Work hard! Your days to study”

If Age is less than 10 then prints the message “Oh! Kid your days to cry”

Use Switch statement.

Answer:

#include <iostream.h>
#include <conio.h>

void main()
{
     int UserAge;
     cout<<"Enter the age: ";
     cin>>UserAge;

     switch(UserAge>45)
     {
     case 1:
     cout<<"You are old stay at home and wait for call";
     break;
     }

     switch(UserAge>30&&UserAge<45)
     {
     case 1:
     cout<<"Hey! man enjoy your life with your kids";
     break;
     }

     switch(UserAge>20&&UserAge<30)
     {
     case 1:
     cout<<"Cool! Have a search for your best suit";
     break;
     }

     switch(UserAge>10&&UserAge<20)
     {
     case 1:
     cout<<"Work hard! Your days to study";
     break;
     }

     switch(UserAge<10)
     {
     case 1:
     cout<<"Oh! Kid your days to cry";
     }

     getch();
}






Posted in: C++ Exercises

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .