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:

  1. If Else Statement In C++ If else statement in c++ Its general form is:- If...
  2. If Statements In C++ If statements in c++ It is used to test the...
  3. Manipulators In C++ Manipulators Manipulators are operators used with the insertion operator <<...
  4. Type Conversion In C++ Type Conversion In C++ This process of converting one predefined...
  5. C++ Cast Explicit type conversion (casts) in c++ or c++ cast It...