
HP Prime Tutorial Series, by Edward Shore and Klaas Kuperus: #1
WHILE, INPUT, KILL
HP Prime Program: TARGET. TARGET is a game where you provide a guess to get a
desired number. If you miss, the calculator will tell you if number is higher and lower.
At the end of the game, the calculator gives you how may picks you needed to get
the target number.
WHILE: Repeat a number of commands while a specific condition is test.
WHILE condition is true DO
commands
END;
Access: Tmplt, 3. Loop, 5. WHILE
Caution: Watch your ENDs! Make sure an END is with each loop and the program
itself. Press the soft key Check to check your work.
INPUT: Creates an input screen for variables. On the HP Prime, the input can asked
for more than one input. TARGET demonstrates INPUT with one prompt.
One Variable:
INPUT(variable, "title", "label", "help text")
Multi-Variable:
INPUT(list of variables, "title", list of "labels", list
of "help text")
Note: Pressing Cancel will store a 0 in variable. You may include code of what to do if
the user presses Cancel, but it is not required.
Access: Cmds, 6. I/O, 5. INPUT
KILL: Terminates program execution. Nothing dies, I promise.
Access: Tmplt. 1. Block, 3. KILL
Program:
EXPORT TARGET()
BEGIN
LOCAL C:=0, N:=RANDINT(1,20), G:=-1;
WHILE G≠N DO
C:=C+1;
INPUT(G,"Guess?","GUESS:","1 - 20");
IF G==0 THEN
KILL;
END;
IF G < N THEN
MSGBOX("Higher");
END;
IF G > N THEN
MSGBOX("Lower");
END;
END;
MSGBOX("Correct! Score: "+C);
END;
Try it and of course, you can adjust the higher
limit. Here is something for you to try with
TARGET:
1. Add a limited amount of guesses.
2. Can you display the list of guesses?