switch case cpp number of same casees code example

Example 1: c++ switch multiple cases

#include <iostream> 
using namespace std; 
  
int main() { 
    // variable declaration 
	int input;
	switch(input){
	case 1: case 2: case 3: case 4:
		//executes if input is 1, 2, 3, or 4
		break;
	case 5: case 6: case 7:
		//executes if input is 5, 6, or 7
        break;
	default:
		//executes if input isn't any of the cases
    }
    return 0; 
}

Example 2: 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
}

Tags:

Cpp Example