The last thing to do is to put all we have done together so that the game can be played. We need to repeat the guessing until either the player gives up (exit) or guesses correctly.
Things to do here.
1) we will need a loop to keep playing the game until it is won or stopped
2) we need to count the number of guesses the player has had so we can tell them how many they took.
3) We need to tell the player how many cows and bulls they have each time.
We already wrote the following definitions.
createFourDigits() - makes the computer chosen number
GetUserChoice() - gets the latest guess from the player
ValidateUserGuess(userchoice) - checks that the player made a valid guess
checkBullsCows(computerNumber,userChoice) - checks for cows and bulls
We now need to put them all together - I decided to write a further definition called playGame() that runs the game calling the above functions when needed.
More on Functions / Procedures (parameters)
More on Functions and Procedures (video lessons)
Below is the code for setting up the variables.
The above is just before we start the main loop that continues until the game is won or exited.
Below is my complete code for this playGame definition - use if you are totally stuck.