Exercise 1.8

The switch statement of Section 1.4 displays a different consolation message based on the number of wrong guesses. Replace this with an array of four string messages that can be indexed based on the number of wrong guesses.

The first step is to define the array of string messages in which to index. One strategy is to encapsulate them in a display function that, passed the number of incorrect user guesses, returns the appropriate consolation message. Here is a first implementation. Unfortunately, it is not correct. Do you see the problems?

 const char* msg_to_usr( int num_tries ) { static const char* usr_msgs[] = { "Oops! Nice guess but not quite it.", "Hmm. Sorry. Wrong again.", "Ah, this is harder than it looks, isn't it?", "It ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.