Let’s play a game
We’re all familiar with number-guessing games. Let’s use what we’ve learned in this chapter to write a game in PowerShell. This is a common challenge set in many programming tutorials, so we’re not going to be any different. In the UK, it is sometimes called the Brucie Game because of its similarity to the popular UK TV gameshow Bruce Forsyth’s Play Your Cards Right. The Brucie bonus here is that we get to learn something.
The program generates a random integer between 1 and 100. We then need to get user input in the form of another integer. We compare the guess with the hidden number and decide whether it’s right. If it is, we go to the end of the program. If it isn’t, then we need to decide whether it is too high or too low and output an appropriate message before going back and asking for another guess. We can represent this as a flow chart, which will be helpful when it comes to writing our code: