Question
Bulls and Cows is a guessing game where you try to guess a four digit code. (Note: each number in the code must be distinct)
Bulls and Cows is a guessing game where you try to guess a four digit code. (Note: each number in the code must be distinct) When a number is guessed and a digit is in the correct location, then that is a bull. When a digit is in the number, but in the incorrect location, then that is a cow. So if the code is 2894, and the user guesses 4698. Then that is "1 bull and 2 cows" because '9' is in the correct location and '4' and '8' are in the code but are currently in the wrong location. The guessing continues until the code is guessed in the correct order... "4 bulls"! This website will give you a feel for the game. http://www.mathsisfun.com/games/bulls-and-cows.html To emulate our version, click on "Options" and select 0-9, 4 Codes. Bulls and Cows is a guessing game where you try to guess a four digit code. (Note: each number in the code must be distinct) When a number is guessed and a digit is in the correct location, then that is a bull. When a digit is in the number, but in the incorrect location, then that is a cow. So if the code is 2894, and the user guesses 4698. Then that is "1 bull and 2 cows" because '9' is in the correct location and '4' and '8' are in the code but are currently in the wrong location. The guessing continues until the code is guessed in the correct order... "4 bulls"! This website will give you a feel for the game. http://www.mathsisfun.com/games/bulls-and-cows.html To emulate our version, click on "Options" and select 0-9, 4 Codes.
The requirements are as follow:
You must get the number as a single integer with four digits.
If too many digits, get number again.
If not enough digits, assume the missing digits are zero.
If repeated digits, get number again.
You must allow the game to be played repeatedly without ending the program between games.
Typing 'y' causes program to be run again. Anything else exits the game.
You must store the code in a vector of ints.
Randomly generate the numbers to guess and output it.
Get the random seed from the user.
No 'endl' after 'Goodbye'.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started