data-structures · beginner · ~15 min

Name a colour

Map enum values to strings.

Challenge

Define enum Color { RED, GREEN, BLUE }; and implement const char *color_name(enum Color c) returning "red", "green", or "blue". Return "unknown" for anything else.

Starter code

enum Color { RED, GREEN, BLUE };

const char *color_name(enum Color c) {
    /* TODO */
    return "unknown";
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.