Skip to content

Instantly share code, notes, and snippets.

@Developerayo
Last active April 10, 2019 09:07
Show Gist options
  • Save Developerayo/01af1c575afe09092e7e4b97d0f6c465 to your computer and use it in GitHub Desktop.
Save Developerayo/01af1c575afe09092e7e4b97d0f6c465 to your computer and use it in GitHub Desktop.
Switch case example in C++
#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