Guess the number/With feedback: Difference between revisions

mNo edit summary
 
(5 intermediate revisions by 3 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,028 ⟶ 2,029:
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
Short n // We'll just do 1..10 to get the idea
Short n
 
void local fn buildInterfaceBuildInterface
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
Line 2,046 ⟶ 2,047:
 
void local fn newGame
CFRange r = fn RangeMake( 1, 10 )
Short i
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
for i = 1 to 10 : button i, Yes : next // Enable all numbers
textlabel 14, @"🔴" // Not found yet
end fn
 
void local fn doDialogDoDialog( 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 button: tag,fn NonewGame // Disable numberAgain
case n if: tagtextlabel ==14, n@"🟢" // Found
ControlRangeSetEnabled( r, textlabel 14,No @"🟢")
button 11, Yes
button 12, Yes
case < elsen //: Givetextlabel us14, a hint@"➡️"
case > n : iftextlabel tag14, < n@"⬅️"
textlabel 14, @"➡️"
else
textlabel 14, @"⬅️"
end if
end if
case 11 : end
case 12 : fn newGame
end select
case _windowWillClose : end
Line 2,078 ⟶ 2,074:
end fn
 
on dialog fn doDialog
fn buildInterface
fn newGame
on dialog fn doDialogDoDialog
handleevents
 
handleevents
</syntaxhighlight>
{{out}}
<pre>
 
</pre>
 
 
Line 4,672 ⟶ 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}}==
305

edits