Switch: falling-through behavior : Switch « Language « C++






Switch: falling-through behavior

Switch: falling-through behavior

#include <iostream>
using namespace std;
int main(void)
{
   char grade;
   cout << "Enter your grade: ";
   cin >> grade;
   switch (grade)
   {
   case 'a':case 'A':
      cout << "Your average must be between 90 - 100" 
           << endl;
      break; 
   case 'b':
   case 'B':
      cout << "Your average must be between 80 - 89" 
           << endl;
      break;
   case 'c':
   case 'C':
      cout << "Your average must be between 70 - 79" 
           << endl;
      break;
   case 'd':
   case 'D':
      cout << "Your average must be between 60 - 69" 
           << endl;
      break;
   default: 
      cout << "Your average must be below 60" << endl;
   }
return 0;
}


           
       








Related examples in the same category

1.A switch statement in actionA switch statement in action
2.Deliberately falls through the caseDeliberately falls through the case