0

```
Problem Statement
Number-Guessing Game Assignment
Write a program for a number-guessing game. Each player will be given 10 attempts to key in a 4-digit number to guess the randomly generated number. All four digits of the computer-generated number MUST be different and the left-most digit cannot be zero. Create a menu that has 4 options as follows:
1) To register number of participants and name
2) To start the game
3) To show ranking
4) To quit
The descriptions for the options are as below:
Option 1
User will be asked to key in the number of players (maximum 5 players) that challenge each other for top ranking. Their name will then be taken in one by one. Assume the names will not exceed 30 characters including spaces.
Option 2
When this option is chosen, the screen will be cleared and the first 4-digit random number generated will be displayed. This number is disclosed here for us to check whether the program is working correctly or not. It is not meant for the player to cheat. Once the number is shown, we will be asked to press any key to continue and the screen will be cleared so that the first player will not know the answer. Then, the first player will be called upon. The player needs to press any key to start the game. You need to do proper validations for the input numbers. The player will be asked to key in the number again if the input is not valid. Invalid inputs are not counted as an attempt. (none digit)
Each valid number which is input by the player will be analysed and a hint will be given (except for last attempt). The hint mentions how many digits are placed correctly (denoted by C), how many digits are not in the number at all (denoted by W), and how many digits are in the number but are positioned wrongly (denoted by P). For example, if the computer-generated number is 5314, the following shows some of the inputs and their respective hints.
1234 1C1W2P – 1 digit wrong,1 digit right position,2 digit right but position wrong
1435 0C0W4P – 4 digit right but position wrong
1354 2C0W2P – 2 digits wrong,2digits right but position wrong
3154 1C0W3P – 1 digit wrong, 3 digits right but position wrong
When the player successfully guesses the number, a congratulatory message is shown to tell player how many attempts had been made to guess the number. If player doesn’t get the number within 10 attempts, a sorry message is shown.
When first player’s game is over, the screen will be cleared after pressing a key. The computer will then generate another new 4-digit number for the second player and reveal it before it is cleared. Then the second player will be called upon and the process continues until the last player.
Option 3
The players will be ranked according to their number of attempts used to guess the number. Player with the least attempts ranked the top. If two players have the same number of attempts, the one who used less time wins. So, you also need to time each player during their game besides recording the number of attempts.
Option 4
When this option is chosen, display “Bye!” and end the program.
Note
- For time, use difftime(time_t, time_t) function and include <ctime> header
- For random number, use rand() and include <cstdlib> header
the example output:
```