Switch Statement In C++
Switch statement in c++
C++ provides a multi way decision statement known as switch. It successively tests the value of an expression against a list of constant values. When a match is found the statement associated with that constant are created.
General form
Switch (expression)
{
Case constant 1:
Statement;
Break;
Case constant 2:
Statement;
Break;
Case constant 3:
Statement;
Break;
Case constant n:
Statement;
Break;
}
This program illustrates a switch case construct.
#include<iostream.h>
#include<conio.h>
Void main ()
{
Int n;
Clrscr ();
Cout<<”\n enter the numbers of Weeks’s day (1-7):”;
Cin>>n;
Switch (n)
{
Case 1: cout<<”\n Sunday”;
Break;
Case 2: cout<<”\n Monday”;
Break;
Case 3: cout<<”\n Tuesday”;
Break;
Case 4: cout<<”\n Wednesday”;
Break;
Case 5: cout<<”\n Thursday”;
Break;
Case 6: cout<<”\n Friday”;
Break;
Case 7: cout<<”\n Saturday”;
Break;
Default: cout<<”\n wrong number”;
}
getch ();
}
Related posts:
- If Else Statement In C++ If else statement in c++ Its general form is:- If...
- If Statements In C++ If statements in c++ It is used to test the...
- Manipulators In C++ Manipulators Manipulators are operators used with the insertion operator <<...
- Type Conversion In C++ Type Conversion In C++ This process of converting one predefined...
- C++ Cast Explicit type conversion (casts) in c++ or c++ cast It...