Number Guessing Game

Learn about infinite looping and use it to perform nondeterministic repetition.

Problem

Write a program that generates a secret a number (0–9) that the user guesses. The program prompts the user to enter a guess and gives feedback, such as "too big" or "too small." The program ends when the correct answer is entered.

I have a secret number (0 - 9), Can you guess it?
=> (you type 9)
Too big!
=> (you type 4)
Too Small!
=> (you type 5)
Correct! You guessed 3 times.
Number guessing game

Purpose

  • Branching with ...