// Figure 7.6 Function to print a value of type color // FILE: DispEnum.cpp #include enum color {red, green, blue, yellow}; // DISPLAYS THE VALUE OF this_color int write_color (color this_color) // IN: color to be printed as string // Pre : this_color is assigned a value. // Post: The value of this_color is displayed as a string. // Returns: Status flag indicating if execution successful. { // Local data ... int status; // indicates if function executes successfully // Print correct color as string literal. status = true; switch (this_color) { case red: cout << "red"; break; case green: cout << "green"; break; case blue: cout << "blue"; break; case yellow: cout << "yellow"; break; default: status = false; cerr << "*** ERROR: Invalid color for value." << endl; } // end switch return status; } // end write_color