How to resolve the algorithm Guess the number step by step in the Plain TeX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number step by step in the Plain TeX programming language
Table of Contents
Problem Statement
Write a program where the program chooses a number between 1 and 10. A player is then prompted to enter a guess. If the player guesses wrong, then the prompt appears again until the guess is correct. When the player has made a successful guess the computer will issue a "Well guessed!" message, and the program exits. A conditional loop may be used to repeat the guessing until the user is correct.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number step by step in the Plain TeX programming language
Source code in the plain programming language
\newlinechar`\^^J
\edef\tagetnumber{\number\numexpr1+\pdfuniformdeviate9}%
\message{^^JI'm thinking of a number between 1 and 10, try to guess it!}%
\newif\ifnotguessed
\notguessedtrue
\loop
\message{^^J^^JYour try: }\read -1 to \useranswer
\ifnum\useranswer=\tagetnumber\relax
\message{You win!^^J}\notguessedfalse
\else
\message{No, it's another number, try again...}%
\fi
\ifnotguessed
\repeat
\bye
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Scala programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Arithmetic numbers step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Tokenize a string with escaping step by step in the VBA programming language