C++ Switch Case || Basic Program || C++
In this, we are going to see the topic of Switch case in C++.

This is a very basic program of Switch Case in which we are going to just print the case only.

The code given below can be used for TURBO C++ Compiler:-

#include<iostream.h>
#include<conio.h>

void main()
{
    clrscr();
    cout<<"\n **** This Program is of Switch Case **** \n";
    int val;
    cout<<"Enter a number from 1 to 4 to select the case\n";
    cin>>val;

    switch (val)
    {
    case 1:
        cout<<"You selected Case 1\n";
        break;
    
    case 2:
        cout<<"You selected Case 2\n";
        break;

    case 3:
        cout<<"You selected Case 3\n";
        break;

    case 4:
        cout<<"You selected Case 4\n";
        break;
    
    default:
        cout<<"Oops!! Your input is not accepted.\n";
        cout<<"Please read the instructions carefully\n";
        break;
    }
    cout<<"Thank You !!";

    getch();
}
  
    

The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int main()
{
    cout<<"\n **** This Program is of Switch Case **** \n";
    int val;
    cout<<"Enter a number from 1 to 4 to select the case\n";
    cin>>val;

    switch (val)
    {
    case 1:
        cout<<"You selected Case 1\n";
        break;
    
    case 2:
        cout<<"You selected Case 2\n";
        break;

    case 3:
        cout<<"You selected Case 3\n";
        break;

    case 4:
        cout<<"You selected Case 4\n";
        break;
    
    default:
        cout<<"Oops!! Your input is not accepted.\n";
        cout<<"Please read the instructions carefully\n";
        break;
    }
    cout<<"Thank You !!";

    return 0;
}
  
    

#ENJOYCODING




1 Comments

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post