Displaying days from enum data type with sequence re-order

 

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 from enum data type, restarting the sequence

To show: Another simple enumeration data type C++ program example

 

// enumeration data type

#include <iostream>

using namespace std;

 

// enum definition

enum Days

{

 

Tuesday,

Wednesday,

Thursday,

Friday,

Saturday,

Sunday,

Monday

};

 

// Global variable i and Days

int i;

// enum data type declaration

Days d = Thursday;

 

int main(void)

{

// Converted by integral promotion.

i = d;

 

cout<<"i = "<<i<<"\n";

cout<<"Tuesday = "<<Tuesday<<"\n";

cout<<"Wednesday = "<<Wednesday<<"\n";

cout<<"Thursday = "<<Thursday<<"\n";

cout<<"Friday = "<<Friday<<"\n";

cout<<"Saturday = "<<Saturday<<"\n";

cout<<"Sunday = "<<Sunday<<"\n";

cout<<"Monday = "<<Monday<<"\n";

return 0;

}

 

Output example:

 

i = 2

Tuesday = 0

Wednesday = 1

Thursday = 2

Friday = 3

Saturday = 4

Sunday = 5

Monday = 6

Press any key to continue . . .

 

 

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