From 341ec4caa8b7feb88525d3f620a86533104a85aa Mon Sep 17 00:00:00 2001 From: aryanaces <43854758+aryanaces@users.noreply.github.com> Date: Thu, 4 Oct 2018 22:31:07 +0530 Subject: [PATCH] Changed the entire code !! Changed the entire code so as to make it more clear for the people who want to learn the use of switch statement . ^^ --- switch/src/switch.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/switch/src/switch.cpp b/switch/src/switch.cpp index b783d64..1289c6e 100644 --- a/switch/src/switch.cpp +++ b/switch/src/switch.cpp @@ -3,7 +3,7 @@ // Author : John Purcell // Version : // Copyright : Your copyright notice -// Description : Hello World in C++, Ansi-style +// Description : Explanation of Switch statement through a code //============================================================================ #include @@ -11,20 +11,22 @@ using namespace std; int main() { - int value = 4; + char choice; + cout<<"Enter your choice : \n"; + cin>>choice; - switch (value) { - case 4: - cout << "Value is 4." << endl; + switch (choice) { + case 'A': + cout << "You entered the choice A ^^" << endl; break; - case 5: - cout << "Value is 5." << endl; + case 'B': + cout << "You entered the choice B ^^" << endl; break; case 6: - cout << "Value is 6." << endl; + cout << "You entered the choice C ^^" << endl; break; default: - cout << "Unrecognized value." << endl; + cout << "No choice matched , Hence the default case will execute" << endl; } return 0;