Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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
}
Comment

cpp case

#include <iostream>
using namespace std;

int main(){
    int number;
    cout<<"Enter an integer: ";
    cin>>number;

    switch (number){        //switch statement
        case 1:
            cout<<"NUMBER IS 1"<<endl;
            break;
        case 2:
            cout<<"NUMBER IS 2"<<endl;
            break;
        case 3:
            cout<<"NUMBER IS 3"<<endl;
            break;
        case 4:
            cout<<"NUMBER IS 4"<<endl;
        case 5:
            cout<<"NUMBER IS 4 OR 5"<<endl;
            break;
        default:
            cout<<"NUMBER IS NOT FROM 1 TO 5"<<endl;
            break;
    }
    cout<<endl;
    return 0;
}
Comment

switch case c++

int value = 0;
switch (value) {
  case 0:
    // do something
    break;
  case 1: 
    // do something else
    break;
   
  default :
  	// something if anything not match
}
Comment

switch case c++

int a;
cout <<"Enter one number"<<endl; 
cin>>a ;
switch(a){
	case(1): // means ==> if a=1 
		cout<<"Your number is 1";
		break;
	case(2):
		cout<<"Your number is 2";
		break;
	default:
		cout<<"Other cases";
}
Comment

c++ switch case

switch(expr) {
  case 1:
    // do something
    break;
  case 2:
    // do something
    break;
  default:
    // do something
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ switch case break 
Cpp :: c++ for in 
Cpp :: http.begin arduino not working 
Cpp :: factorial in c++ 
Cpp :: random number cpp 
Cpp :: iterating in map/unordered map c++ 
Cpp :: c++ construnctor 
Cpp :: how to put bitset into a string in c++ 
Cpp :: c++ random number 0 to 1 
Cpp :: singleton c++ 
Cpp :: number of lines in c++ files 
Cpp :: flags for g++ compiler 
Cpp :: c++ template example 
Cpp :: cpp initialize multidimensional vector 
Cpp :: check uppercase c++ 
Cpp :: overload stream extract cpp 
Cpp :: double to int c++ 
Cpp :: c vs c++ 
Cpp :: binary representation c++ 
Cpp :: how to use char in c++ 
Cpp :: priority queue c++ 
Cpp :: C++ Vector Iterator Syntax 
Cpp :: initialize vector of vector c++ 
Cpp :: c++ modulo positive 
Cpp :: prisma client 
Cpp :: pointer in return function c++ 
Cpp :: Setting a number of decimals on a float on C++ 
Cpp :: binary search c++ 
Cpp :: doubly linked list in cpp 
Cpp :: c++ program to convert kelvin to fahrenheit 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =