What number am I thinking of?


Problem Statement

Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively.


Plans and pseudocode

Declare var name

Ask the user for their name

Store in name

Declare var guessesTaken

Declare var number

Pick a random number

Store in number

Declare var guess

Ask the user to guess a number

Store in guess


Solution

If (guess = number) then output "Your guess is correct" else output "Guess again"

Demonstration


Next Page
Back