Skip to content

Instantly share code, notes, and snippets.

@juanfal
Created October 17, 2012 12:51
Show Gist options
  • Save juanfal/3905354 to your computer and use it in GitHub Desktop.
Save juanfal/3905354 to your computer and use it in GitHub Desktop.
switch example through student grades
// 03.grades.cpp
// Switch example through student grades
#include <iostream>
#include <cctype>
using namespace std;
int main( )
{
char grade;
cout << "Enter your control grade (A, B, C, D, E or F): ";
cin >> grade;
switch (toupper(grade))
{
case 'A':
cout << "Excellent. "
<< "You need not take the final.\n";
break;
case 'B':
cout << "Very good. ";
grade = 'A';
cout << "Your midterm grade is now "
<< grade << endl;
break;
case 'C':
cout << "Passing.\n";
break;
case 'D':
case 'F':
cout << "Not good. "
<< "Go study.\n";
break;
default:
cout << "That is not a possible grade.\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment