Â
In this we are going see a basic program on Enumeration, to define an enum and few variables of the enum type and print their values in C++ Programming Language.
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <conio.h>
void main()
{
enum weekday
{
monday = 2, // value assigned is 2
tuesday, //since no value is assigned, the previous value is incremented, hence assigned value is 3
wednesday, // value assigned is 4
thursday, // value assigned is 5
friday, // value assigned is 6
saturday, // value assigned is 7
sunday = 1 // value assigned is 1
};
weekday x = friday;
cout << "The value of x is: " << x;
getch();
}
//.......Coded by SAHIL SHAIKH
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
int main()
{
enum weekday
{
monday = 2, // value assigned is 2
tuesday, //since no value is assigned, the previous value is incremented, hence assigned value is 3
wednesday, // value assigned is 4
thursday, // value assigned is 5
friday, // value assigned is 6
saturday, // value assigned is 7
sunday = 1 // value assigned is 1
};
weekday x = friday;
cout << "The value of x is: " << x;
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