Enumerations Program in C++

This C++ Program which illustrates the use of enumerations. The program creates an enumeration of months, creates an enumeration variable, assigns it a month value and prints a comment on the current month.

Here is source code of the C++ program which illustrates the use of enumerations. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. /*
  2.  * C++ Program to Illustrate the use of Enumerations
  3.  */
  4.  
  5. #include<iostream>
  6. using namespace std;
  7.  
  8. enum Month {January = 1 ,February = 2, March = 3, April = 4, May = 5,
  9.             June = 6, July = 7, August = 8, September = 9, October = 10,
  10.             November = 11, December = 12};
  11.  
  12. int main()
  13. {
  14.     Month month;
  15.     month = August;
  16.  
  17.     cout << "The month is August." << endl;
  18.     /* Printing comments on current Month */
  19.     if (month >= March && month <= May)
  20.         cout << "Yay, It is Spring!" << endl;
  21.     else if (month >= June && month <= August)
  22.         cout << "It is Summer, Who needs an Ice Cream?" << endl;
  23.     else if (month >= September && month <= November)
  24.         cout << "I am enjoying Autumn, Aren't You?" << endl;
  25.     else
  26.         cout << "Ooh, It is very cold outside! It's Winter!" << endl;
  27. }

$ g++ main.cpp
$ ./a.out
The month is August.
It is Summer, Who needs an Ice Cream?

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.