Understanding Enumerations
Having had trouble understanding enumerations, i decided to have a brief trial and error session with my compiler to observe how they work.
Code:
enum colors {red,yellow,green,brown,blue,pink,black} mycolor;
From this i continued to conclude that mycolor could have assigned any of the defined constants but would not compile using a constant that was not defined (logically). ie:
Is ok.
Errors.
I also assume that you cannot assign a value to an enumeration.
What i do not understand is the purpose of enums. I could see then serving a similar purpose to a switch statement or perhaps an if conditional however i do not understand how you would use them in this fashion. I would really appreciate some guidance on this issue, or perhaps simply an example of how an enum would be used in a program.
Thank you