Day 2 Program — Guess!

Here’s at least one way to make the program from class. I’ve added some spaces to make it more readable, but they’re NOT required on the calculators.

Define guess()=
Prgm
 Local num, trial, guessed, guesses

 guesses:=0
 guessed:=false

 num:=randInt(1,10)
 Disp num

 While not guessed
   Request "Guess (1-10)?",trial,0
   guesses:=guesses+1
   
   If trial=num Then
     guessed:=true
   ElseIf trial<num Then
     Disp "Too low!"
   ElseIf trial>num Then
     Disp "Too high!"
   EndIf
  EndWhile

  local prt
  prt := string(guesses)
  Disp "You got it in" & prt & " guesses."

EndPrgm

Leave a Reply

Your email address will not be published. Required fields are marked *