Question: Codebreaker Game Specification Code-breaker is a number guessing game. The computer chooses a 4-digit secret code at random. The player must guess what that number
Codebreaker Game Specification
Code-breaker is a number guessing game. The computer chooses a 4-digit secret code at random. The player must guess what that number is. After each guess, the player is given a score that tells him how many digits he guessed correctly and that are in the proper position, and how many digits in the guess are in the secret code, but the guess is in the wrong position.
For example:
| Secret Code | Guess | Score |
| 1234 | 1243 | 2.2 |
| 1234 | 2345 | 0.3 |
| 1234 | 5234 | 3.0 |
To program Code Breaker, write the following methods:
// puts four random numbers from zero to 9 into a four-integer array. void GetSecretCode(int digits[], int size);
// Gets the individual guess digits from the player. void GetGuessFromPlayer(int digits[], int size);
// returns the number of user digits that exist in the secret code int CountMatches(int userCode[], int secretCode, int size);
// returns the number of exactly correct guesses int CountExactMatches(int userCode[], int secretCode[], int size);
At the top of your program, put the following numeric constants. Use them to help you write the necessary loops, and to allow you to change the behavior of the program by changing the number:
size = 4; guesses = 6;
The program should initially provide for 4 digits and 6 guesses. If the user guesses the correct code (i.e. a score of 4.0) in 6 guesses or less, he wins.
Use CountMatches() and CountExactMatches() to help you compose the score. Note that the second component of the score is matches minus exact matches. Store these in variables called score1 and score2. You can print the overall score like this:
printf(%d.%d, score1, score2);
After each guess by the user, print the score and ask the user for a new guess, until he achieves a score of 4.0 or he runs out of guesses.
When the game is over, ask the user if they want to play again. If the user answers Y, then start a new game. Otherwise, exit the program.
Could someone help me figure this out?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
