Guess the number/With feedback (player): Difference between revisions

Add Red
m (→‎{{header|Phix}}: replaced with gui version)
(Add Red)
Line 2,760:
 
You may execute this program with '<tt>raku program</tt>' or with '<tt>raku program min max</tt>'. Raku creates a usage for us if we don't give the right parameters. It also parses the parameters for us and provides them via <tt>$min</tt> and <tt>$max</tt>. We use multi-subs to provide two MAIN subroutines so the user is able to choose between min and max parameters and no parameters at all, in which case min is set to 0 and max to 100.
 
=={{header|Red}}==
<lang rebol>Red[]
 
lower: 1
upper: 100
print ["Please think of a number between" lower "and" upper]
 
forever [
guess: to-integer upper + lower / 2
print ["My guess is" guess]
until [
input: ask "Is your number (l)ower, (e)qual to, or (h)igher than my guess? "
find ["l" "e" "h"] input
]
if "e" = input [break]
either "l" = input [upper: guess] [lower: guess]
]
 
print ["I did it! Your number was" guess]</lang>
{{out}}
<pre>
Please think of a number between 1 and 100
My guess is 50
Is your number (l)ower, (e)qual to, or (h)igher than my guess? car
Is your number (l)ower, (e)qual to, or (h)igher than my guess? l
My guess is 25
Is your number (l)ower, (e)qual to, or (h)igher than my guess? h
My guess is 37
Is your number (l)ower, (e)qual to, or (h)igher than my guess? l
My guess is 31
Is your number (l)ower, (e)qual to, or (h)igher than my guess? h
My guess is 34
Is your number (l)ower, (e)qual to, or (h)igher than my guess? e
I did it! Your number was 34
</pre>
 
=={{header|REXX}}==
1,808

edits