Basic Enumeration program




In this we are going to see a basic program on Enumeration using C++ Programming Language.



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

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

void main()
{
    //defining an enum called colour
    enum colour 
    {
        violet, //by default value o is assigned
        indigo, //value is incremented by 1, hence value assigned is 1
        blue,   //value assigned is 2
        green,  // value assigned is 3
        yellow, // value assigned is 4
        orange, //value assigned is 5
        red     // value assigned is 5
    };          // the defining of an enum must end with a semicolon
    //different ways of defining variables of enumeration type colour
    colour c1 = green;
    colour c2(orange);
    colour c3{blue};
    cout << "The value of colour 1 is: " << c1 << endl;
    cout << "The value of colour 2 is: " << c2 << endl;
    cout << "The value of colour 3 is: " << c3 << endl;
    getch();
}
//.......Coded by SAHIL SHAIKH



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

#include <iostream>
using namespace std;

int main()
{
    //defining an enum called colour
    enum colour 
    {
        violet, //by default value o is assigned
        indigo, //value is incremented by 1, hence value assigned is 1
        blue,   //value assigned is 2
        green,  // value assigned is 3
        yellow, // value assigned is 4
        orange, //value assigned is 5
        red     // value assigned is 5
    };          // the defining of an enum must end with a semicolon
    //different ways of defining variables of enumeration type colour
    colour c1 = green;
    colour c2(orange);
    colour c3{blue};
    cout << "The value of colour 1 is: " << c1 << endl;
    cout << "The value of colour 2 is: " << c2 << endl;
    cout << "The value of colour 3 is: " << c3 << endl;
    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