Showing posts with label Enumeration in C. Show all posts
Showing posts with label Enumeration in C. Show all posts

Tuesday, 3 February 2015

Enumeration in C++

Structure of the Problem Requirements  

Enumeration is a user-defined type whose value is restricted to one of several explicitly named constants(enumerators). enum is the key word that is use for this. In this code first we declare global enum declaration, in which we have four values and then in main program we can make a instance of enum and then use it.

Source Code

#include <iostream>
using namespace std;
enum number { one = 1, two = 4, three = 9, four = 16};
int main() {
number n;
n = four;
cout<<"\n\n\t ****** Enumeration ******** \n\n";
cout << "Four Square : " << n << endl;
return 0;
}

Output of the Program

Enumeration in C++