Answers for "c++ awitch statements"

C++
33

c++ switch case statement

switch (n)
{
    case 1: // code to be executed if n = 1;
        break;
    case 2: // code to be executed if n = 2;
        break;
    default: // code to be executed if n doesn't match any cases
}
Posted by: Guest on March-12-2020
2

switch statement 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;
}
Posted by: Guest on November-09-2020
0

c++ awitch statements

var = 1

switch (var):

  case 1:
	break; // Code that is executed if var is 1

  case 2:
	break; // Code that is executed if var is 2

  default:
	break; // Code that is executed if no cases match
Posted by: Guest on November-23-2020

Browse Popular Code Answers by Language