DevelopersSociety

Tuesday, December 9, 2014

C++ Tutorial- Program- 10- Switch Statement

//developerssociety.blogspot.com via- Programmarsarmy.blogspot.com

Code:

#include<iostream>  
using namespace std;
main()
{
int n;
cout<<"Enter any number between 1-6:";
cin>>n;

cout<<"You entered:"<<n<<endl;

cout<<"Name of Students\n"
    <<"================\n"
    <<" 1- Usaid\n 2- Rahim\n 3- Rida\n 4- Aysha\n 5- Jannat\n 6- Imtiaz"
    <<"\n================"<<endl<<endl;
  if(n>0&&n<=10)
  
 switch(n)
{
 case 1:
        cout<<n<<"= usaid "<<endl;
        cout<<"================"<<endl;
  break;
 case 2:
        cout<<n<<"= rahim"<<endl;
        cout<<"================"<<endl;
  break;
 case 3:
        cout<<n<<"= rida "<<endl;
        cout<<"================"<<endl;
  break;
 case 4:
        cout<<n<<"= ayesha "<<endl;
        cout<<"================"<<endl;
  break;
 case 5:
       cout<<n<<"= Jannat "<<endl;
        cout<<"================"<<endl;
  break;
 case 6:
        cout<<n<<"= Imtiaz "<<endl;
        cout<<"================"<<endl;
  break;
}

}

Output:

No comments:

Post a Comment