Guess the number/With feedback: Difference between revisions

Guess the number/With feedback in Gambas, Minimal BASIC, Qbasic, Run BASIC, True BASIC and Yabasic
(Guess the number/With feedback in Gambas, Minimal BASIC, Qbasic, Run BASIC, True BASIC and Yabasic)
Line 370:
 
=={{header|BASIC}}==
 
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">100 L% = 1
Line 389 ⟶ 388:
==={{header|BASIC256}}===
{{works with|BASIC256 }}
<syntaxhighlight lang="basic256">Min = 5: Max = 15
Min = 5: Max = 15
chosen = int(rand*(Max-Min+1)) + Min
print "Guess a whole number between "+Min+" and "+Max
Line 403 ⟶ 401:
if guess = chosen then print "Well guessed!"
end if
until guess = chosen</syntaxhighlight>
</syntaxhighlight>
Output:(example)
<pre>Guess a whole number between 5 and 15
<pre>
Guess a whole number between 5 and 15
Enter your number 10
Sorry, your number was too high
Line 413 ⟶ 409:
Sorry, your number was too low
Enter your number 8
Well guessed!</pre>
 
</pre>
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Randomize
Dim guess As Integer, max As Integer = 20
Dim n As Integer = Int(Rnd * max) + 1
Print "Guess which number I've chosen in the range 1 to "; max; Chr(10)
Do
Print " Your guess : "
Input guess
If guess > n And guess <= 20 Then
Print "Your guess is higher than the chosen number, try again"
Else If guess = n Then
Print "Correct, well guessed!"
Break
Else If guess < n And guess >= 1 Then
Print "Your guess is lower than the chosen number, try again"
Else
Print "Your guess is inappropriate, try again"
End If
Loop
 
End</syntaxhighlight>
 
==={{header|IS-BASIC}}===
Line 434 ⟶ 456:
250 END SELECT
260 LOOP UNTIL NR=GU</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
{{trans|Tiny Craft Basic}}
<syntaxhighlight lang="qbasic">100 RANDOMIZE
110 LET T = 0
120 LET N = 20
130 LET R = INT(RND *N)+1
140 PRINT "GUESS A WHOLE NUMBER BETWEEN 1 AND";N
150 REM LOOP
160 LET T = T+1
170 PRINT "ENTER YOUR NUMBER ";
180 INPUT G
190 IF G <> R THEN 220
200 PRINT "YOU GUESSED IT IN";T;"TRIES."
210 GOTO 360
220 REM ENDIF
230 IF G > R THEN 260
240 IF G < 1 THEN 260
250 PRINT "SORRY, YOUR NUMBER WAS TOO LOW"
260 REM ENDIF
270 IF G < R THEN 300
280 IF G > 100 THEN 300
290 PRINT "SORRY, YOUR NUMBER WAS TOO HIGH"
300 REM ENDIF
310 IF G >= 1 THEN 320
320 IF G <= 100 THEN 340
330 PRINT "THAT WAS AN INVALID NUMBER"
340 REM ENDIF
350 IF G <> R THEN 150
360 END</syntaxhighlight>
 
==={{header|QB64}}===
Line 458 ⟶ 510:
PRINT "You won!"; secretNumber%%; "was the secret number!"</syntaxhighlight>
{{out}}
<pre>The computer has chosen a secret number between 1 and 10.
<pre>
The computer has chosen a secret number between 1 and 10.
What is your guess? -1
Please enter a number between 1 and 10!
Line 473 ⟶ 524:
Your guess is HIGHER than the target.
What is your guess? 2
You won! 2 was the secret number!</pre>
 
</pre>
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">CLS
RANDOMIZE TIMER ' set a seed based on system time
nmax = 20
chosen = INT(RND * nmax) + 1
 
PRINT "Guess a whole number between 1 a"; nmax; CHR$(10)
DO
INPUT "Enter your number"; guess
IF guess < n OR guess > nmax THEN
PRINT "That was an invalid number"
EXIT DO
ELSE
IF guess < chosen THEN PRINT "Sorry, your number was too low"
IF guess > chosen THEN PRINT "Sorry, your number was too high"
IF guess = chosen THEN PRINT "Well guessed!"
END IF
LOOP UNTIL guess = chosen
END</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="vb">nmin = 5
nmax = 15
chosen = int( rnd( 1) * (nmax-nmin+1)) +nmin
print "Guess a whole number between "; nmin; " and "; nmax
[loop]
input "Enter your number "; guess
if guess < nmin or guess > nmax then
print "That was an invalid number"
end
else
if guess < chosen then print "Sorry, your number was too low"
if guess > chosen then print "Sorry, your number was too high"
if guess = chosen then print "Well guessed!": end
end if
if guess <> chosen then [loop]</syntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">RANDOMIZE
LET nmax = 20
LET chosen = int(rnd*nmax)+1
PRINT "Guess a whole number between 1 a"; nmax; chr$(10)
DO
INPUT prompt "Enter your number ": guess
IF guess < n or guess > nmax then
PRINT "That was an invalid number"
EXIT DO
ELSE
IF guess < chosen then PRINT "Sorry, your number was too low"
IF guess > chosen then PRINT "Sorry, your number was too high"
IF guess = chosen then PRINT "Well guessed!"
END IF
LOOP until guess = chosen
END</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="vb">nmin = 5
nmax = 15
chosen = int(ran(nmax-nmin+1)) + nmin
print "Guess a whole number between ", nmin, " and ", nmax
repeat
input "Enter your number " guess
if guess < nmin or guess > nmax then
print "That was an invalid number"
end
else
if guess < chosen print "Sorry, your number was too low"
if guess > chosen print "Sorry, your number was too high"
if guess = chosen print "Well guessed!"
fi
until guess = chosen</syntaxhighlight>
 
=={{header|Batch File}}==
2,122

edits