Last active
April 10, 2019 09:07
-
-
Save Developerayo/01af1c575afe09092e7e4b97d0f6c465 to your computer and use it in GitHub Desktop.
Switch case example in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main () { | |
// local variable declaration: | |
char grade = 'D'; | |
switch(grade) { | |
case 'A' : | |
cout << "Excellent!" << endl; | |
break; | |
case 'B' : | |
case 'C' : | |
cout << "Well done" << endl; | |
break; | |
case 'D' : | |
cout << "You passed" << endl; | |
break; | |
case 'F' : | |
cout << "Better try again" << endl; | |
break; | |
default : | |
cout << "Invalid grade" << endl; | |
} | |
cout << "Your grade is " << grade << endl; | |
return 0; | |
} | |
// This would produce the below result | |
// You passed | |
// Your grade is D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment