I’m new to C and I have been reading concepts and example code in a book titled “C Programming in easy steps”.
So, I type in this example program, character for character:
#include <stdio.h>
int main()
{
/* declare a sequence of constants */
enum colors
{ RED=1,YELLOW,GREEN,BROWN,BLUE,PINK,BLACK };
/* Declare a variable of the enumerated data type */
enum colors fingers;
/* assign valid constants from the colors list */
/* -----THIS IS THE ERROR LINE BELOW---------- */
fingers = (enum colors) PINK + BROWN;
/*-display the value in the variable */
printf("Value: %d\n", fingers);
return 0;
}
and I get this error:
13 C:\Users\mjohearn\Documents\pet projects\constant types NOT WORKING\enumtypes.cpp invalid conversion from `int' to `main()::colors'
For some reason the compiler does not recognize fingers.
If anyone could help me solve this problem, I would really appreciate it.
Try
I believe the cast operator binds more tightly than the addition operator.