Displaying days in numbers representation using enumeration (enum)

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Displaying days in numbers representation using enum data type and re-ordering the sequence

To show: The enum data type C++ program example resetting the enum sequence order

 

// enum data type

#include <iostream>

using namespace std;

 

// enum definition, re-ordering the sequence

enum days {mon = 1, tue, wed, thu, fri, sat, sun};

 

void main(void)

{

// Declaring enum data type

enum days day_count;

 

cout<<" Simple day count\n";

cout<<" using enum\n";

for(day_count = mon; day_count <= sun; )

{

cout<<" "<<day_count<<"\n";

day_count = days(day_count + 1);

}

}

 

Output example:

 

Simple day count

using enum

1

2

3

4

5

6

7

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index