Switch statement is use instead of if else condition in programming. If statement 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.
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 !"; } }
The example is shitty programming. All case statements execute the same line of code. Change it to something like:
ReplyDeletecase 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.