Guess the number/With feedback: Difference between revisions

 
(15 intermediate revisions by 8 users not shown)
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|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="vbnet">100 cls
110 nmax = 20
120 chosen = int(rnd(1)*nmax)+1
130 print "Guess a whole number between 1 a ";nmax;chr$(10)
140 do
150 input "Enter your number: ",guess
160 if guess < n or guess > nmax then
170 print "That was an invalid number"
180 exit do
190 else
200 if guess < chosen then print "Sorry, your number was too low"
210 if guess > chosen then print "Sorry, your number was too high"
220 if guess = chosen then print "Well guessed!"
230 endif
240 loop until guess = chosen
250 end</syntaxhighlight>
 
==={{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|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
<syntaxhighlight lang="qbasic">100 CLS
110 RANDOMIZE 1
120 L = 20
130 X = INT(RND(1)*L)+1
140 PRINT "Guess a whole number between 1 a ";L;CHR$(10)
150 'do
160 INPUT "Enter your number: ", N
170 IF N < N OR N > L THEN PRINT "That was an invalid number" : GOTO 230
180 'else
190 IF N < X THEN PRINT "Sorry, your number was too low"
200 IF N > X THEN PRINT "Sorry, your number was too high"
210 IF N = X THEN PRINT "Well guessed!"
220 IF N <> X THEN GOTO 150
230 END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
Line 434 ⟶ 493:
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 LET T = T+1
160 PRINT "ENTER YOUR NUMBER ";
170 INPUT G
180 IF G <> R THEN 210
190 PRINT "YOU GUESSED IT IN";T;"TRIES."
200 GOTO 310
210 IF G > R THEN 240
220 IF G < 1 THEN 240
230 PRINT "SORRY, YOUR NUMBER WAS TOO LOW"
240 IF G < R THEN 270
250 IF G > 100 THEN 270
260 PRINT "SORRY, YOUR NUMBER WAS TOO HIGH"
270 IF G >= 1 THEN 300
280 IF G <= 100 THEN 300
290 PRINT "THAT WAS AN INVALID NUMBER"
300 IF G <> R THEN 140
310 END</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
<syntaxhighlight lang="qbasic">100 CLS
120 L = 20
130 X = INT(RND(1)*L)+1
140 PRINT "Guess a whole number between 1 a ";L;CHR$(10)
150 'do
160 INPUT "Enter your number: "; N
170 IF N < N OR N > L THEN PRINT "That was an invalid number" : GOTO 230
180 'else
190 IF N < X THEN PRINT "Sorry, your number was too low"
200 IF N > X THEN PRINT "Sorry, your number was too high"
210 IF N = X THEN PRINT "Well guessed!"
220 IF N <> X THEN GOTO 150
230 END</syntaxhighlight>
 
==={{header|QB64}}===
Line 458 ⟶ 558:
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 ⟶ 572:
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}}==
Line 637 ⟶ 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,031 ⟶ 1,207:
 
=={{header|Craft Basic}}==
<syntaxhighlight lang="basic">titlelet "hilo"n = int(rnd * 100) + 1
 
bgcolor 0, 180, 0
cls
wait
 
let n = int(rnd * 100) + 1
 
do
Line 1,059 ⟶ 1,229:
loop g <> n
 
alert "you guessed the number in ", t, " tries"</syntaxhighlight>
 
end</syntaxhighlight>
 
=={{header|Crystal}}==
Line 1,265 ⟶ 1,433:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
print "Guess a number between 1 and 100!"
n = randomrandint 100
repeat
g = number input
write g
if error = 1
print "You must enter a number!"
elif g > n
print " is too high"
elif g < n
print " is too low"
.
until g = n
.
print " is correct"
Line 1,344 ⟶ 1,512:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import extensions;
public program()
{
int randomNumber := randomGenerator.evalnextInt(1,10);
console.printLine("I'm thinking of a number between 1 and 10. Can you guess it?");
bool numberCorrect := false;
Line 1,858 ⟶ 2,026:
 
return</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
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
 
</syntaxhighlight>
 
 
=={{header|Genie}}==
Line 4,441 ⟶ 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,776 ⟶ 4,956:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
import "random" for Random
 
305

edits