The goal of this assignment is to learn the following:
In this assignment you will write a program using the skills you have already learned. Write a number guessing game that generates a random number between 1 and 100, inclusively (meaning 1 and 100 should be included). Once a number is generated, ask the user to guess that number and continue asking the until they guess the correct number. You will give the user hints, such as telling them their guess is too high or too low.
Create a new project and name it GuessingGame, and open the main.quorum file.
Your program should:
use statement and
RandomIntegerBetween(integer, integer) action you will need.
You will need to use
Libraries.Compute.Random to create a random number object. You will then need to call the
RandomIntegerBetween(integer, integer) action on that object.
//This line is the use statement.
//Add your Random object here. //Call this action on your Random object. Fill in the parameters with the correct integers.
NOTE: Output and the Online Editor
When running this assignment online, the results of
output won't appear until after the program finishes. This means that if we use
output statements to let the user know if their guess is too low or too high, they won't get any feedback until after they've already guessed correctly. To get around this problem, we can add our output to the beginning of our
input statements instead.
// We can store our "output" in this variable.
text response = "Welcome to the number guessing game. Can you guess my number?"
// Then we can add our variable to the front of our input statement.
integer guess = cast(integer, input(response + " Guess a number between 1 and 100:"))
The input dialog statements are included in the sample output. They are identified as [Input Dialog].
Welcome to the number guessing game. Can you guess my number? [Input Dialog] Guess a number between 1 and 100: 50 My number is less than 50 [Input Dialog] Guess a number between 1 and 100: 25 My number is greater than 25 [Input Dialog] Guess a number between 1 and 100: 38 You guessed my number! Game over.
Can you think of an efficient way to guess the number every time? Describe a guessing strategy for this game.
In the next tutorial, we will discuss Assignment 3.3, which describes Key Press Madness - Audio in Quorum..