Anonymous user
Guess the number/With feedback: Difference between revisions
→{{header|REXX}}: re-did the entire program, more and better error messages, expanded vocabulary, added a bingo statement. -- ~~~~
(→Spidermonkey Version: Forgot to check if number is in range.) |
(→{{header|REXX}}: re-did the entire program, more and better error messages, expanded vocabulary, added a bingo statement. -- ~~~~) |
||
Line 1,561:
=={{header|REXX}}==
<lang rexx>/*REXX program that plays the guessing (the number) game. */
low=1 /*lower range for
high=100 /*upper range for
try=0 /*number of valid attempts.
r=random(1,100) /*get a random
lows='
highs='
er!='*** error! ***'
do ask=0; say; say prompt; say; pull g; g=space(g); say
do validate=0
select
▲ say "guess the number, it's between" low 'and',
when g=='' then iterate▼
▲ high '(inclusive) ---or--- QUIT:'
when \datatype(g,'N') then say er! g "isn't numeric"
▲ if g=='QUIT' then exit
otherwise leave validate
iterate ask
▲ call ser g "isn't a whole number"
end
▲ call ser g 'is below the lower limit of' low
▲ end
▲ call ser g 'is above the higher limit of' high
▲ iterate
try=try+1
if g
if g>r then what=word(highs,random(1,words(highs)))
else what=word( lows,random(1,words( lows)))
say 'your guess of' g "is" translate(what'.',,"_")
end /*forever*/
if try==1 then say 'Gadzooks!!! You guessed the number in right away!'
▲say 'Congratulations!, you guessed the number in' try tries"."
=={{header|Ruby}}==
|