Demonstrate enum types with day of week - C++ Data Type

C++ examples for Data Type:enum

Description

Demonstrate enum types with day of week

Demo Code

#include <iostream>
using namespace std;
//specify enum type
enum days_of_week { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
int main()//from   w  ww .  j  a va2  s. c o m
{
   days_of_week day1, day2;   //define variables of type days_of_week
   day1 = Mon;
   day2 = Thu;
   int diff = day2 - day1;
   cout << "Days between = " << diff << endl;
   if(day1 < day2)
      cout << "day1 comes before day2\n";
   return 0;
}

Result


Related Tutorials