BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Sunday, March 27, 2011

FOP CHAPTER 5

STUDY DATE : 2 MAR 2011
TOPIC : IF ELSE ... SWICTH CASE......

EXAMPLE :

AGE   =    GENERATION
1-6      =  kids
7-12    =  child
13-21  =  teenagers 
22-30  =  adult
> 31    = old

if ..... else 

#include <iostream.h>
main ( )
{
declare variable
int age ;
// input
cout << " enter your AGE : " ;
cin >> age ;
//if else statement
if (age > = 1 II age <=6)
{cout << " you are kids ! " ;
else if ( age >=7 II age < = 12 )
{cout << '" you are child ! " ;
else if ( age >=13 II age <=21 )
{cout << " you are teenagers ! " ;
else if ( age <=22 II age <=30 )
{cout << " you are adult ! " ;
else if ( age > 30 )
{cout << " you are old ! " ;
else
{cout << "invalid selection" , ;
return 0 ;
}

swicth...case

#include < iostream.h>
main ( )
//declre variable
int age ;
//input
cout << " enter your age : " ;
cin >> age;
// swicth ... case statement
{ case ('age'>=1 II 'age' <= 6) : cout << " you are kids ! " ; break ;
case ( 'age'>=7 II 'age' <=12) : cout <<  " you are child ! " ; break ;
case ('age'>= 13 II 'age' <= 21) : cout << " you are teengers ! " ; break ;
case ( 'age' >= 22 II 'age' <=30) : cout << "you are adult ! " ; break ;
case ( 'age >30 ) : cout << " you are old ! " ; break ;
default : cout << " invalid selection " ;
}
return 0 ;
}

0 comments: