4.5.The switch statement

The switch statement used for multiple selection that will allow only integer value and only one character.

syntax:

switch(condition)
{
	case constant 1:	statement 1;	break;
	case constant 2:	statement 2;	break;
	...
	case constant n:	statement n;	break;
	default:		statement;
}

Example 1:

#include<iostream.h>
#include<conio.h>
void main()
{
	int num;
	cout<<"Enter Number: "; cin>>num;
	switch(num)
	{
		case 1:	cout<<"Monday";         
                        break;
		case 2:	cout<<"Tuesday";        
                        break;
		case 3:	cout<<"Wednesday";      
                        break;
		default:cout<<"Can be input only num 1, 2 and 3";
	}
	getch();
}
Suggest Edit