October 1999
Beginner
304 pages
7h 11m
English
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 ...Read now
Unlock full access