Write a program that will generate, but not display, a three-digit "target" number that has three distinct digits. Then, inputs a maximum of eight user guesses and, for each guess, outputs the number of "hits" and "matches" in the guess. The program stops when the user guesses the correct number or runs out of guesses.
For example, if the target number is 427, the guess 207 has one hit (7) and one match (2), whereas the guess 749 has two matches (4 and 7), and the guess 327 has two hits (2 and 7).
The Program
At a minimum, your program will need to contain and make use of the two user-defined functions, placed in the "game" library, as follows:
A function that generates and returns a new number matching the task specifications. Its prototype is
int generateNewNumber();
A function that takes as input two numbers one and two, and outputs, through reference parameters hits and matches, the number of hits and matches between the two numbers. Its prototype is
void getHitsAndMatches( int one, int two, int & hits, int & matches );
Examples:
Note: user entered values are shown in bold.
Example 1:
After every trial the program displays the number of hits and matches.
Enter your guess (it must be between 100 and 999): 345
You got 1 hits and 2 matches
Enter your guess (it must be between 100 and 999): 354
You got 3 hits and 0 matches
It took you 2 tries to guess 354 correctly.
Example 2:
The program should perform some input checking. Minimally, it should check if the input number is in the range.
Enter your guess (it must be between 100 and 999): 45
Enter your guess (it must be between 100 and 999): 8888
Enter your guess (it must be between 100 and 999): 677
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 247
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 137
You got 2 hits and 0 matches
Enter your guess (it must be between 100 and 999): 837
You got 1 hits and 1 matches
Enter your guess (it must be between 100 and 999): 139
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 187
You got 3 hits and 0 matches
It took you 6 tries to guess 187 correctly.
Example 3:
If the user didn't guess the number then the program displays a message that includes the "target".
.................................................. ....
You got 0 hits and 0 matches
Enter your guess (it must be between 100 and 999): 333
You got 1 hits and 0 matches
The number you didn't guess correctly was 361
Important Notes:
The Files subdirectory for this assignment contains skeleton files for the library files,
game.h and game.cpp
the "RandomInt" library files, RandomInt.h and RandomInt.cpp
as well as the application file, guess.cpp.
In the Files subdirectory for this assignment, there is a Makefile that you can use to build the final executable program. If your program does not contain any syntax errors and you have not changed the names of any of the files, make will build the executable file guess.
Caution: after you copy the Makefile, you may need to ensure that target command lines begin with a TAB space rather than several individual spaces.
The Makefile will be supplied automatically for you during the marking procedure. It is essential that you name your program files as specified.
Compile often. It is better to make small incremental changes and then compile, then it is to add large amounts of code and then try to compile.
You should add comments to your code.
Test your program. (In particular, be sure to test it on turing before you submit it.) Does it behave as expected when valid data are entered?
During the marking procedure, your program may be run with a data set that contains different values than those in the example data set