Jump to content

Guess the number: Difference between revisions

m
→‎{{header|BASIC}}: sorted out various issues
m (→‎{{header|QBasic}}: removed double sub-header)
m (→‎{{header|BASIC}}: sorted out various issues)
Line 581:
160 PRINT "Well guessed!"</lang>
 
==={{header|QBasic}}, Gives Hints===
<lang qbasic>supervisor:
GOSUB initialize
Line 620:
WEND</lang>
 
===QBasic, More Polished Version===
A more polished version of this program in QBasic/QB/VB-DOS
<lang qbasic>
Line 676:
==={{header|QB64}}===
The following is a modification of the above polished version in QBasic with explanations of differences.
<lang QB64qbasic>Randomize Timer 'Moved to the head as it is an initialization statement,
'although it could be placed anywhere prior to the Rnd() function being called.
 
Line 721:
End</lang>
 
===QB64 Alternative Version, Gives Hints===
==={{header|ZX Spectrum Basic}}===
ZX Spectrum Basic has no [[:Category:Conditional loops|conditional loop]] constructs, so we have to emulate them here using IF and GO TO.
<lang zxbasic>10 LET n=INT (RND*10)+1
20 INPUT "Guess a number that's between 1 and 10: ",g
30 IF g=n THEN PRINT "That's my number!": STOP
40 PRINT "Guess again!"
50 GO TO 20</lang>
 
==={{header|QB64}}===
 
Single-line "Guess the Number" program QBasic QB64 from Russia
<lang QB64qbasic>
1 IF Russia = 0 THEN Russia = 2222: RANDOMIZE TIMER: num = INT(RND * 100) + 1: GOTO 1 ELSE IF Russia <> 0 THEN INPUT n: IF n < num THEN PRINT "MORE": GOTO 1 ELSE IF n > num THEN PRINT "less": GOTO 1 ELSE IF n = num THEN PRINT "da": END ELSE GOTO 1 'DANILIN Russia 9-9-2019 guessnum.bas
</lang>
The multi-line equivalent of the above.
<lang QB64qbasic>'Based on DANILIN Russia 9-9-2019 guessnum.bas
1 If c% = 0 Then
c% = 1
Line 756 ⟶ 747:
End If</lang>
 
===QB64 Expanded Range, Auto-Interactive===
 
<b>Note:</b> This is off-task, as there is no user interaction.<br/><br/>
==={{header|QB64}}===
<lang QB64>Program from Russia guesses 1 out of a billion
<lang qbasic>
 
h1=0: h2=10^39:t=1:f=0: Randomize Timer 'daMilliard.bas
human = Int(Rnd*h2) 'human DANILIN
comp = Int(Rnd*h2) 'comp
Line 786 ⟶ 777:
7 40 39 MORE
8 40 40 win by 8 steps</pre>
 
==={{header|ZX Spectrum Basic}}===
ZX Spectrum Basic has no [[:Category:Conditional loops|conditional loop]] constructs, so we have to emulate them here using IF and GO TO.
<lang zxbasic>10 LET n=INT (RND*10)+1
20 INPUT "Guess a number that's between 1 and 10: ",g
30 IF g=n THEN PRINT "That's my number!": STOP
40 PRINT "Guess again!"
50 GO TO 20</lang>
 
=={{header|BASIC256}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.