The High-Low Game Program is a very simple user program that illustrates a few programming constructs to implement the classic "guess a number" game.
The calculator will pick a random integer from 1 to 100 and will count the number of guesses you use to find the number. If you enter 0 for a guess, the game will end.
| G | The user's guess |
| N | The number of guesses used |
| X | The number to find |
Some characters on the HP 38G, like the store-arrow (\|>), are represented in the listing below by special three-character sequences. For a full list of these sequences, you can refer to the HP 38G Character Translation Codes page.
0\|>G: Initialize guess variable
0\|>N: Initialize guess counter
INT(RANDOM*100)+1\|>X: Generate number to guess
DO
INPUT G;"High-Low Game";"Guess:";"Enter guess (1-100) or 0 to quit";G: Get user's guess
ERASE:N+1\|>N: Clear display, increment guess counter
IF G\=/ 0 THEN If guess is non-zero, test value:
IF G>X THEN
DISP 3; " Guess is high!": Display message for high guess
WAIT 2:
END:
IF G<X THEN
DISP 6; " Guess is low!": Display message for low guess
WAIT 2:
END:
ELSE
0\|>X: If guess is zero, set X=0 to end the loop
END
UNTIL The game ends when G=X, either because
G==X the user guessed the number or entered 0
END:
MSGBOX "You used " N " guesses!":
Back to James Donnelly's web site.
Back to the HP 38G page.
Back to the main calculator page.