Guess the number/With feedback: Difference between revisions

(Added various BASIC dialects (Chipmunk Basic, GW-BASIC and MSX Basic))
 
(8 intermediate revisions by 4 users not shown)
Line 812:
 
printf( "Guess the number between %d and %d: ", lower_limit, upper_limit );
fflush(stdout); // Flush the output buffer
 
while( scanf( "%d", &guess ) == 1 ){
Line 1,432 ⟶ 1,433:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
print "Guess a number between 1 and 100!"
n = randomrandint 100
repeat
g = number input
Line 2,025 ⟶ 2,026:
 
return</syntaxhighlight>
 
=={{header|Tiny Craft BasicFutureBasic}}==
<syntaxhighlight lang="basicfuturebasic">10 cls
Short n // We'll just do 1..10 to get the idea
 
void local fn BuildInterface
Short i
window 1, @"Guess the number", ( 0, 0, 340, 120 )
for i = 1 to 10
button i,,, fn StringWithFormat(@"%d", i), ( 26 * i, 60, 40, 22 )
ButtonSetBordered( i, No )
next
button 11,,, @"Quit", ( 38, 10, 95, 32 )
button 12,,, @"Again", ( 200, 10, 95, 32 )
textlabel 13, @"Guess the number:", ( 112, 85, 200, 22 )
textlabel 14,, ( 158, 30, 100, 22 ) // Hints here
filemenu 1 : menu 1, -1, No // Build but disable File menu
editmenu 2 : menu 2, -1, No // Build but disable Edit menu
end fn
 
void local fn newGame
CFRange r = fn RangeMake( 1, 10 )
ControlRangeSetEnabled( r, Yes ) // Enable number buttobns
button 11, No // Disable Quit button
button 12, No // Disable Again button
n = rnd( 10 ) // Choose a random number
textlabel 14, @"🔴" // Not found yet
end fn
 
void local fn DoDialog( evt as Long, tag as Long )
CFRange r = fn RangeMake( 1, 10 )
select evt
case _btnClick
button tag, No
select tag
case 11 : end // Quit
case 12 : fn newGame // Again
case n : textlabel 14, @"🟢" // Found
ControlRangeSetEnabled( r, No )
button 11, Yes
button 12, Yes
case < n : textlabel 14, @"➡️"
case > n : textlabel 14, @"⬅️"
end select
case _windowWillClose : end
end select
end fn
 
fn buildInterface
fn newGame
on dialog fn DoDialog
handleevents
 
220 shell "pause"</syntaxhighlight>
 
 
=={{header|Genie}}==
Line 4,608 ⟶ 4,664:
Well done! You guessed it.
</pre>
 
=={{header|Tiny Craft Basic}}==
<syntaxhighlight lang="basic">10 cls
 
20 let r = int(rnd * 100) + 1
 
30 print "hilo game"
40 print "guess the nusmber between 1 and 100"
 
50 rem loop
 
60 let t = t + 1
 
70 input "guess: ", g
 
80 if g <> r then 110
 
90 print "you guessed it in ", t ," tries."
100 goto 220
 
110 rem endif
 
120 if g > r or g < 1 then 140
 
130 print "too low"
 
140 rem endif
 
150 if g < r or g > 100 then 170
 
160 print "too high"
 
170 rem endif
 
180 if g >= 1 and g <= 100 then 200
 
190 print "invalid guess"
 
200 rem endif
 
210 if g <> r then 50
 
220 shell "pause"</syntaxhighlight>
 
=={{header|TUSCRIPT}}==
Line 4,943 ⟶ 4,956:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
import "random" for Random
 
305

edits