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 the guessing game. */
high=100 /*upper range for the guessing game. */
try=0 /*number of valid attempts. */
r=random(1,100) /*get a random number# (low-- ──> high). */
lows='lowtoo_low small too_small too_little below punyunder underneath too_puny'
highs='hightoo_high too_big too_much big above hugeover over_the_top too_huge'
say prompt=centre("guess the number, it's between" low 'and',
high '(inclusive) ───or─── ---or--- QUITQuit:',79,"─")
er!='*** error! ***'
 
do ask=0; say; say prompt; say; pull g; g=space(g); say
do forever
do validate=0
say
select
say "guess the number, it's between" low 'and',
when g=='' then iterate
high '(inclusive) ---or--- QUIT:'
if g== when abbrev('QUIT',g,1) then exit
say
pull g when words(g)\==1 then say er! 'too many /*thisnumbers alsoentered:' uppercases the input.*/g
when \datatype(g,'N') then say er! g "isn't numeric"
say
when \datatype(g,'W') then say call serer! g "isn't a whole number"
g=space(g)
when g<low then say call serer! g 'is below the lower limit of' low
if g=='' then iterate
when g>high then say call serer! g 'is above the higher limit of' high
if g=='QUIT' then exit
otherwise leave validate
 
end end/*select*/
if \datatype(g,'W') then do
iterate ask
call ser g "isn't a whole number"
end iterate/*validate*/
end
if g<low then do
call ser g 'is below the lower limit of' low
iterate
end
 
if g>high then do
call ser g 'is above the higher limit of' high
iterate
end
 
try=try+1
if g==r then leave
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!'
tries='tries'
else say 'Congratulations!, you guessed the number in' try tries"tries."</lang>
if try==1 then do; try='one'; tries="try"; end
say
say 'Congratulations!, you guessed the number in' try tries"."
say
exit
/*---------------------------SER subroutine-------------------*/
ser: say; say '*** error ! ***'; say arg(1); say; return</lang>
 
=={{header|Ruby}}==