Anonymous user
Guess the number/With feedback (player): Difference between revisions
Guess the number/With feedback (player) (view source)
Revision as of 23:06, 27 October 2018
, 5 years ago→with positive integers: added/changed comments and statements, simplified the program.
(→with positive numbers: added/changed comments and whitespace, simplfied some statements.) |
(→with positive integers: added/changed comments and statements, simplified the program.) |
||
Line 2,263:
=={{header|REXX}}==
===with positive integers===
This version only handles positive integers
<lang rexx>/*REXX
if
if
?= random(low, high) /*generate random number from low->high*/
$= "──────── Try to guess my number (it's between " /*part of a prompt message.*/
g=
do
if
say /*display a blank line before prompt. */
say /*display a blank line after prompt. */
g= (low + (high - low) / 2) / 1
if g=oldg then g= g + 1
say 'My guess is' g
if g=? then leave
if g>? then info= right(' Your guess is too high.', 60, "─")
else info= right(' Your guess is too low.' , 60, "─")
say info
end /*try*/
say /*stick a fork in it, we're all done. */
say 'Congratulations! You guessed the secret number in' # "tries."</lang>
'''output''' shown is from playing several games:
<pre style="height:70ex">
──────── Try to guess my number (it's between 1 and 1000 inclusive)
My guess is 500.5
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 1 and 500.5 inclusive):
My guess is 250.75
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 250.75 and 500.5 inclusive):
My guess is 375.625
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 250.75 and 375.625 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 313.1875 and 375.625 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 313.1875 and 344.40625 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 328.796875 and 344.40625 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 336.601563 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 332.699219 inclusive):
My guess is 330.748047
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 328.796875 and 330.748047 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.772461 and 330.748047 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 329.772461 and 330.260254 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 329.772461 and 330.016358 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.89441 and 330.016358 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.955384 and 330.016358 inclusive):
My guess is 329.985871
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 329.985871 and 330.001115 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.993493 and 330.001115 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.997304 and 330.001115 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.99921 and 330.001115 inclusive):
My guess is 330.000163
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.999687 and 330.000163 inclusive):
My guess is
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between 329.999925 and 330.000163 inclusive):
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 329.999925 and 330.000044 inclusive):
My guess is 329.999985
───────────────────────────────────── Your guess is too low.
──────── Try to guess my number (it's between
My guess is
──────────────────────────────────── Your guess is too high.
──────── Try to guess my number (it's between 329.999985 and 330.000015 inclusive):
My guess is
Congratulations! You guessed the secret number in
</pre>
|