Page 52 - Modular_V2.0_C++_Flikpbook
P. 52
case 'u':
DOSBox 0.74, Cpu speed: max 100% cycles,
cout<<"Entered character is vowel"; Enter a character: A
break; Entered character is vowel
default:
cout<<"Entered character is consonant";
} DOSBox 0.74, Cpu speed: max 100% cycles,
getch(); Enter a character: M
} Entered character is consonant
Clickipedia
The expression of switch statement must be of integer or character type. Floating-point
constants are not allowed.
DIFFERENCE BETWEEN IF AND SWITCH STATEMENTS
Following are some differences between if and switch statements:
The if statement can test any type of expressions (integer, floating-point, logical, relational,
etc), while switch can test only integer expressions.
The if statement encloses multiple statements inside curly braces { }. This is shown below:
if(condition)
{
statement1;
statement2;
}
The switch statement does not encloses multiple cases inside curly braces { }, as each case is
written separately. This is shown below:
switch (value)
{
case 1 :
statement1;
statement2;
break;
case 2:
statement1;
statement2;
break;
}
The break can be used inside switch body but cannot be used inside if body. For example,
50
Touchpad MODULAR (Ver. 2.0)

