Wednesday, March 30, 2011


jom blaja pasal if...else statement & switch...case statement

ok bdasarkan table kt ats . kite bole wt program dlm 2 jenis bentuk . sama ade dlm bntuk if...elseataupon switch...case . ok now kite wt dlm bentuk if..else statement dlu k ..

IF...ELSE STATEMENT
#include<iostream.h>
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//if...else statement
if(age>=1||age<=6)
{cout<<"you are kids !!";}
else if(age>=7||age<=12)
{cout<<"you are child !!";}
else if(age>=13||age<=21)
{cout<<"you are teenager !!";}
else if(age>=22||age<=30)
{cout<<"you are adult !!";}
else if(age>30)
{cout<<"you are old !!";}
else
{cout<<"Invalid selection";}
return 0;
}

SWITCH...CASE STATEMENT
#include<iostream.h>
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//switch...case statement
switch(age)
{
case('age'>=1||'age'<=6):cout<<"you are kids !!";break;
case('age'>=7||'age'<=12):cout<<"you are kids !!";break;
case('age'>=13||'age'<=21):cout<<"you are kids !!";break;
case('age'>=22||'age'<=30):cout<<"you are kids !!";break;
case('age'>30):cout<<"you are kids !!";break;
default:cout<<"Invalid selection";
}
return 0;
}

No comments:

Post a Comment