Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C++ I need help writing a Bulls and Cows game. The game is to only run ONCE in other words you get only one
In C++ I need help writing a Bulls and Cows game. The game is to only run ONCE in other words you get only one chance to guess the random number before you have to execute the file again and try another random five digit number. Also, there must be at least two exceptions one for repeat of double digits and one for an invalid input. I will post the following problem and code that I have written so far.
(40 points) Implement the game "Bulls and Cows." The program uses a vector of five different digits in the range 0 to 9, e.g. 12345, but not 11346, called a secret number, and it is the user's task to discover this number by repeated guesses. Say the number to be guessed is 67895 and the user guesses 71245; the response should be 1 cow and 1 bull because the user got one digit (7) right but in the wrong position and one digit (5) correct in the right position. The guessing continues until the user gets five bulls and wins, that is, has five digits correct and in the right positions. Print out the number of tries after winning. For the grading purposes add an option that displays the secret number if asked. Also, the secret number should be hard-coded (fixed) in the program. Your program should use at least two exceptions: Invalid_number_of_digits and Duplicated_digits, and possibly Invalid_input. (40 points) Implement the game "Bulls and Cows." The program uses a vector of five different digits in the range 0 to 9, e.g. 12345, but not 11346, called a secret number, and it is the user's task to discover this number by repeated guesses. Say the number to be guessed is 67895 and the user guesses 71245; the response should be 1 cow and 1 bull because the user got one digit (7) right but in the wrong position and one digit (5) correct in the right position. The guessing continues until the user gets five bulls and wins, that is, has five digits correct and in the right positions. Print out the number of tries after winning. For the grading purposes add an option that displays the secret number if asked. Also, the secret number should be hard-coded (fixed) in the program. Your program should use at least two exceptions: Invalid_number_of_digits and Duplicated_digits, and possibly Invalid_inputStep 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