Mar 19, 2007

C++ Program to input age to find out teen, young or old

This program will accept age from the user and according to age appropriate message would be display like baby , child , teenager, young or old. In this program I have used Logical operator (and operator)

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int age;
cout<<"enter the age in year(s)";
cin>>age;
if (age<1)
{
cout << "invalid age";
}

if(age>=1 && age<=3)
{
cout<<"baby"<<endl;
}

if(age>3 && age<=12)
{
cout<<"child"<<endl;
}

if(age>=13 && age<20)
{
cout<<"teenager"<<endl;
}

if(age>=20 && age<=45)
{
cout<<"young"<<endl;
}

if(age>45)
{
cout<<"old"<<endl;
}

getch();
}

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive