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

c++ switch case break

#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

PREVIOUS NEXT
Code Example
Cpp :: C++ switch cases 
Cpp :: how to iterate from second element in map c++ 
Cpp :: http.begin() error 
Cpp :: array and for loop in c++ 
Cpp :: sort stl 
Cpp :: c++ typedef 
Cpp :: c++ constructors 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: c++ return multiple values 
Cpp :: c++ check if vector is sorted 
Cpp :: number of words in c++ files 
Cpp :: error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ 
Cpp :: c++ call method in same class 
Cpp :: c++ init multidimensional vector 
Cpp :: c++ cout colored output xcode 
Cpp :: cpp insert overload operator 
Cpp :: c++ Program for Sum of the digits of a given number 
Cpp :: cpp cin 
Cpp :: c++ get character from string 
Cpp :: functors in c++ 
Cpp :: debugging c/c++ with visual studio code 
Cpp :: what is c++ standard library 
Cpp :: c++ array size 
Cpp :: swap elements array c++ 
Cpp :: how to reverse a string in c++ 
Cpp :: how to specify the number of decimal places in c++ 
Cpp :: max in c++ 
Cpp :: a square plus b square plus c square 
Cpp :: letter occurrence in string c++ 
Cpp :: convert kelvin to Fahrenheit 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =