Enums using switch Case




In this we are going to see basic program on Enumeration, using Switch Case in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -

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

void main()
{
    enum choice
    {
        heads,
        tails
    };
    choice mychoice = heads;
    switch (mychoice)
    {
    case heads:
        cout << "The choice is Heads";
        break;
    case tails:
        cout << "The choice is Tails";
        break;
    default:
        cout << "The choice is neither Heads or Tails";
    }
    getch();
}

//.......Coded by SAHIL SHAIKH


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

int main()
{
    enum choice
    {
        heads,
        tails
    };
    choice mychoice = heads;
    switch (mychoice)
    {
    case heads:
        cout << "The choice is Heads";
        break;
    case tails:
        cout << "The choice is Tails";
        break;
    default:
        cout << "The choice is neither Heads or Tails";
    }
    return 0;
}

//.......Coded by SAHIL SHAIKH


#ENJOY CODING

Post a Comment

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

Previous Post Next Post