Friday 8 August 2014

Write a Program in C++ which Use Switch statement

Structure of the Problem Requirements 


In this problem we learn how to make a Switch statement in C++. Switch statement is use instead of if else condition in programming. If is well organized statement which reduce the complexity of code and increase the readability of your program and code. Just assign the condition input in the switch variable and put their related data in specific case.Here is the Source code of this problem which will help you in better learning . 

Source Code 


#include<iostream>
using namespace std;
int main ()
{
int num=0;
cout<<" Enter Number Between 0-9 \n ";
cin>>num;
switch (num)
{
case 0:
cout<<" You press : " << num;
break;
case 1:
cout<<" You press : " << num;
break;
case 2:
cout<<" You press : "<< num;
break;
case 3:
cout<<" You press : "<< num;
break;
case 4:
cout<<" You press : "<< num;
break;
case 5:
cout<<" You press : "<< num;
break;
case 6:
cout<<" You press : "<< num;
break;
case 7:
cout<<" You press : "<< num;
break;
case 8:
cout<<" You press : "<< num;
break;
case 9:
cout<<" You press : "<< num;
break;
default :
cout<<" You Press Something Else !";
}
}

Output of the Program











Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

1 comments: Post Yours! Read Comment Policy!▼
Important Note:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. The example is shitty programming. All case statements execute the same line of code. Change it to something like:

    case 0:
    cout << "I see you like 0" << endl;
    break;
    case 1:
    cout << "Ah, you're a 1 type of guy" << endl;
    break;

    Something like that. Basically, different statements.

    ReplyDelete