Guess the number/With feedback: Difference between revisions
m
syntax highlighting fixup automation
Not a robot (talk | contribs) (Add VTL-2) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19:
{{trans|Python}}
<
print("Guess my target number that is between #. and #. (inclusive).\n".format(target_min, target_max))
Line 41:
I answer > target {print(‘ Too high.’)}
print("\nThanks for playing.")</
{{out}}
Line 76:
=={{header|Action!}}==
<
BYTE x,n,min=[1],max=[100]
Line 94:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Guess_the_number_with_feedback.png Screenshot from Atari 8-bit computer]
Line 109:
=={{header|Ada}}==
<
with Ada.Text_IO;
procedure Guess_Number_Feedback is
Line 159:
end loop;
Guess_Number (Lower_Limit, Upper_Limit);
end Guess_Number_Feedback;</
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.win32}}
<
main:(
Line 209:
OD;
print( ( "That's correct!", newline ) )
)</
{{out}}
<pre>
Line 235:
=={{header|AppleScript}}==
<
property minLimit : 1
property maxLimit : 100
Line 273:
end try
end repeat
end run</
=={{header|Arturo}}==
<
while ø [
try? [
Line 288:
]
else -> print "\tInvalid input!"
]</
{{out}}
Line 305:
=={{header|AutoHotkey}}==
<
MaxNum = 99999999999
Line 335:
}
TotalTime := Round((A_TickCount - TotalTime) / 1000,1)
MsgBox, 64, Correct, The number %RandNum% was guessed in %Tries% tries, which took %TotalTime% seconds.</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f GUESS_THE_NUMBER_WITH_FEEDBACK.AWK
BEGIN {
Line 367:
exit(0)
}
</syntaxhighlight>
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
<
110 U% = 10
120 N% = RND(1) * (U% - L% + 1) + L%
Line 385:
210 Q = G% = N%
220 NEXT
230 PRINT "THE GUESS WAS EQUAL TO THE TARGET."</
==={{header|BASIC256}}===
{{works with|BASIC256 }}
<
Min = 5: Max = 15
chosen = int(rand*(Max-Min+1)) + Min
Line 404:
end if
until guess = chosen
</syntaxhighlight>
Output:(example)
<pre>
Line 417:
==={{header|IS-BASIC}}===
<
110 RANDOMIZE
120 LET UP=10:LET LO=1 ! Limits
Line 433:
240 PRINT "Well guessed! Numner of tips:";COUNT
250 END SELECT
260 LOOP UNTIL NR=GU</
==={{header|QB64}}===
Note that <code>INPUT</code> only allows the user to type things that can fit in the variable it's storing to. Since we're storing to a byte, we don't have to worry about the user typing any non-numbers.
<
DIM guess AS _BYTE ' the player's guess
Line 456:
END SELECT
LOOP UNTIL guess%% = secretNumber%%
PRINT "You won!"; secretNumber%%; "was the secret number!"</
{{out}}
<pre>
Line 477:
=={{header|Batch File}}==
<
:A
Line 493:
echo You won! The number was %number%
pause>nul
goto A</
=={{header|BBC BASIC}}==
<
Max% = 10
chosen% = RND(Max%-Min%+1) + Min% - 1
Line 514:
ENDCASE
UNTIL FALSE
END</
=={{header|BCPL}}==
<
static $( randstate = ? $)
Line 559:
wrch('*N')
play(min, max, rand(min, max))
$)</
{{out}}
<pre>Guess the number
Line 587:
The number range is hardcoded at the start of the program (<tt>1:"d"</tt> being 1 to 100), but can easily be changed.
<
<*2\_$\1+%+48*">",,#v>#+:&#>#5-:!_0`00p0"hgih"00g>_0"wol"00g!>_48vv1?
\1-:^v"d correctly!"<^,,\,+55,". >"$_,#!>#:<"Your guess was too"*<>+>
:#,_@>"ess" >"eug uoY"></
{{out}}
Line 604:
=={{header|Brat}}==
<
p "Guess a number between 1 and 10."
Line 620:
}
}
}</
=={{header|C}}==
<
#include <stdio.h>
#include <time.h>
Line 647:
return 0;
}</
Demonstration:
Line 666:
=={{header|C sharp}}==
<
class Program
Line 705:
}
}
</syntaxhighlight>
Output:
<pre>The number is between 1 and 10. Make a guess: 1
Line 724:
=={{header|C++}}==
<
#include <cstdlib>
#include <ctime>
Line 751:
return 0;
}</
Output:
<pre>Enter lower limit: 1
Line 771:
=={{header|Caché ObjectScript}}==
<
; get a random number between 1 and 100
set target = ($random(100) + 1) ; $r(100) gives 0-99
Line 799:
write !!,"You guessed the number in "_tries_" attempts."
quit</
{{out}}<pre>SAMPLES>do ^GUESSNUM^
Line 824:
In you module.ceylon file put import ceylon.random "1.3.1";
<
DefaultRandom
}
Line 860:
}
}
}</
=={{header|Clojure}}==
<
(let [start 1
end 100
Line 878:
:else true)
(println "Correct")
(recur (inc i)))))))</
=={{header|CLU}}==
<
po: stream := stream$primary_output()
pi: stream := stream$primary_input()
Line 936:
secret: int := min + random$next(max - min + 1)
play_game(min, max, secret)
end start_up</
{{out}}
<pre>Guess the number
Line 959:
=={{header|COBOL}}==
<
PROGRAM-ID. Guess-With-Feedback.
Line 988:
GOBACK
.</
=={{header|Common Lisp}}==
<
(let ((num-guesses 0)
(num (+ (random (1+ (- max min))) min))
Line 1,007:
(= guess num)))
(format t "You got the number correct on the ~:r guess!~%" num-guesses)))
</syntaxhighlight>
Output:
<pre>CL-USER> (guess-the-number-feedback 1 1024)
Line 1,032:
=={{header|Crystal}}==
{{trans|Ruby}}
<
puts "Guess the number between 1 and 10"
Line 1,050:
puts "Please enter an integer."
end
end</
=={{header|D}}==
{{trans|Python}}
<
std.range;
Line 1,084:
writeln(answer < target ? " Too low." : " Too high.");
}
}</
Sample game:
<pre>Guess my target number that is between 1 and 100 (inclusive).
Line 1,108:
=={{header|DCL}}==
<
$ count = 0
$ loop:
Line 1,122:
$ if guess .gt. rnd then $ write sys$output "too large"
$ if guess .ne. rnd then $ goto loop
$ write sys$output "it only took you ", count, " guesses"</
{{out}}
<pre>$ @guess
Line 1,144:
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 1,229:
end.
</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight lang="text">print "Guess a number between 1 and 100!"
n = random 100 + 1
repeat
Line 1,246:
until g = n
.
print " is correct"</
=={{header|EchoLisp}}==
<
;;(read <default-value> <prompt>) prompts the user with a default value using the browser dialog box.
;; we play sounds to make this look like an arcade game
Line 1,267:
(play-sound 'ok )
" 🔮 Well played!! 🍒 🍇 🍓")
</syntaxhighlight>
=={{header|Ela}}==
<
guess () = do
Line 1,306:
ask ()
guess () ::: IO</
=={{header|Elena}}==
ELENA 4.x :
<
public program()
Line 1,335:
}
}
}</
{{out}}
<pre>
Line 1,349:
=={{header|Elixir}}==
{{works with|Elixir|1.2}}
<
def play(lower, upper) do
play(lower, upper, Enum.random(lower .. upper))
Line 1,368:
end
GuessingGame.play(1, 100)</
=={{header|Emacs Lisp}}==
<
(max 100)
(number (+ (random (1+ (- max min))) min))
Line 1,385:
((= guess number)
(setq done t)
(message "Well guessed!")))))</
=={{header|Erlang}}==
<
-module(guess_number).
-export([main/0]).
Line 1,415:
guess(N)
end.
</syntaxhighlight>
{{out}}
<pre>1> c(guess_number).
Line 1,435:
=={{header|Euphoria}}==
<
constant lower_limit = 0, upper_limit = 100
Line 1,453:
puts(1,"You guessed to low.\nTry again: ")
end if
end while</
=={{header|F_Sharp|F#}}==
<
open System
Line 1,487:
0
</syntaxhighlight>
=={{header|Factor}}==
<
formatting
fry
Line 1,515:
[ unparse "Number in range %s, your guess?\n" printf flush ]
[ random '[ _ game-step ] loop ]
bi ;</
=={{header|Fantom}}==
<
class Main
{
Line 1,556:
}
}
</syntaxhighlight>
Sample game:
Line 1,584:
=={{header|FOCAL}}==
<
01.02 A "LOWER LIMIT",L
01.03 A "UPPER LIMIT",H
Line 1,598:
01.16 T "TOO LOW!",!;G 1.1
01.17 T "CORRECT! GUESSES",%4,T,!;Q
01.18 T "TOO HIGH!",!;G 1.1</
{{out}}
Line 1,621:
=={{header|Fortran}}==
{{works with|Fortran|95 and later}}
<
implicit none
Line 1,647:
end if
end do
end program</
Output
<pre>I have chosen a number bewteen 1 and 100 and you have to try to guess it.
Line 1,665:
=={{header|FreeBASIC}}==
<
Randomize
Line 1,686:
End If
Loop
End</
Sample input/output
Line 1,702:
=={{header|Frink}}==
<
target = random[1,100] // Min and max are both inclusive for the random function
guess = 0
Line 1,722:
println["$guess is correct! Well guessed!"]
}
</syntaxhighlight>
{{out}}
Including an example with a non-integer entered.
Line 1,735:
=={{header|Genie}}==
<
/*
Number guessing with feedback, in Genie
Line 1,785:
init
var game = new NumberGuessing(1, 100)
game.start()</
{{out}}
Line 1,823:
=={{header|Go}}==
<
import (
Line 1,851:
}
}
}</
=={{header|Groovy}}==
Based on the Java implementation
<
def rand = new Random() // java.util.Random
def range = 1..100 // Range (inclusive)
Line 1,876:
}
}
</syntaxhighlight>
Example:
<syntaxhighlight lang="text">
The number is in 1..100
Guess the number: ghfvkghj
Line 1,894:
Guess the number: 92
Your guess is spot on!
</syntaxhighlight>
=={{header|Haskell}}==
<
import Control.Monad
import System.Random
Line 1,921:
putStrLn "Try to guess my secret number between 1 and 100."
ask `until_` answerIs ans
</syntaxhighlight>
=={{header|HolyC}}==
<
U8 min = 1, max = 100;
Line 1,943:
if (Str2I64(g) > n)
Print("Your guess was too high.\nTry again: ");
}</
=={{header|Icon}} and {{header|Unicon}}==
<syntaxhighlight lang="icon">
procedure main()
smallest := 5
Line 1,968:
}
end
</syntaxhighlight>
Output:
Line 1,986:
=={{header|J}}==
<
game=: verb define
assert. y -: 1 >. <.{.y
Line 1,996:
smoutput (*x-n){::'You win.';'Too high.';'Too low.'
end.
)</
Note: in computational contexts, J programmers typically avoid loops. However, in contexts which involve progressive input and output and where event handlers are too powerful (too complicated), loops are probably best practice.
Line 2,002:
Example use:
<syntaxhighlight lang="text"> game 100
Guess my integer, which is bounded by 1 and 100
Guess: 64
Line 2,013:
Too low.
Guess: 44
You win.</
=={{header|Java}}==
<
import java.util.Scanner;
public class Main
Line 2,043:
} while (guessedNumber != randomNumber);
}
}</
Demonstration:
<pre>The number is between 1 and 100.
Line 2,060:
=={{header|JavaScript}}==
<
<form id="guessNumber">
<input type="text" name="guess">
Line 2,066:
</form>
<p id="output"></p>
<script type="text/javascript"></
<
function verify() {
Line 2,087:
}
document.getElementById('guessNumber').onsubmit = verify;</
<syntaxhighlight lang
=== Spidermonkey Version ===
<
function main() {
Line 2,135:
main();
</syntaxhighlight>
Example session:
Line 2,155:
{{works with|Julia|0.6}}
<
number = rand(1:n)
print("I choose a number between 1 and $n\nYour guess? ")
Line 2,169:
end
guesswithfeedback(10)</
{{out}}
Line 2,181:
=={{header|Kotlin}}==
<
fun main() {
Line 2,196:
}
}
}</
Sample inout/output
{{out}}
Line 2,213:
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{def game
Line 2,235:
{game {pow 2 32}} // 2**32 = 4294967296
</syntaxhighlight>
Sample inout/output
Line 2,276:
=={{header|Lasso}}==
<
local(
Line 2,308:
#status = true
}
}</
With range value 8 and 73. Correct number 13
Line 2,324:
=={{header|LFE}}==
<
(defmodule guessing-game
(export (main 0)))
Line 2,346:
(: random uniform 10)
(get-player-guess)))
</syntaxhighlight>
From the LFE REPL (assuming the above code was saved in the file "guessing-game.lfe"):
<
> (slurp '"guessing-game.lfe")
#(ok guessing-game)
Line 2,365:
ok
>
</syntaxhighlight>
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
[start]
target = int( rnd( 1) * 100) +1
Line 2,385:
if c >target then print " Your guess was too high."
wend
</syntaxhighlight>
=={{header|LiveCode}}==
<
local tNumber, tguess, tmin, tmax
if lowN is empty or lowN < 1 then
Line 2,416:
end if
end repeat
end guessTheNumber</
Test
<
guessTheNumber --defaults to 1-10
guessTheNumber 9,12
end testGuessNumber</
=={{header|Locomotive Basic}}==
<
20 PRINT "Please specify lower and upper limits":guess=0
30 INPUT " (must be positive integers) :", first, last
Line 2,437:
110 INPUT "That's correct! Another game (y/n)? ", yn$
120 IF yn$="y" THEN 20
</syntaxhighlight>
Output:
Line 2,445:
=={{header|Logo}}==
{{trans|UNIX Shell}}
<
local "number
make "number random :max
Line 2,470:
]
end
</syntaxhighlight>
Sample run:<pre>? guess
Line 2,487:
=={{header|Lua}}==
<
me_win=false
my_number=math.random(1,10)
Line 2,509:
end
end
</syntaxhighlight>
<pre>
Line 2,527:
=={{header|M2000 Interpreter}}==
{{trans|BASIC256}}
<syntaxhighlight lang="m2000 interpreter">
Module GuessNumber {
Read Min, Max
Line 2,555:
}
GuessNumber 5, 15
</syntaxhighlight>
{{out}}
Line 2,561:
=={{header|Maple}}==
<
local number, input;
randomize():
Line 2,577:
end if;
end do:
end proc:</
<syntaxhighlight lang
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
Module[{number = RandomInteger[{min, max}], guess},
While[guess =!= number,
Line 2,590:
ToString@max <> "."]]];
CreateDialog[{"Well guessed!", DefaultButton[]}]];
guessnumber[1, 10]</
=={{header|MATLAB}} / {{header|Octave}}==
{{untested|Octave}}
Tested in MATLAB. Untested in Octave.
<
if nargin < 1 || ~isnumeric(low) || length(low) > 1 || isnan(low)
Line 2,620:
gs = '';
end
end</
=={{header|MAXScript}}==
<syntaxhighlight lang="maxscript">
Range = [1,100]
randomNumber = (random Range.x Range.y) as integer
Line 2,639:
)
)
</syntaxhighlight>
Output:
<syntaxhighlight lang="maxscript">
Enter a number between 1 and 100: 5
Too low!
Line 2,656:
Well guessed!
OK
</syntaxhighlight>
=={{header|Mirah}}==
<
s = System.console.readLine()
Integer.parseInt(s)
Line 2,684:
puts "Please enter an integer."
end
end</
=={{header|Modula-2}}==
<
IMPORT InOut, Random, NumConv, Strings;
Line 2,726:
InOut.WriteString ("Thank you for playing; have a nice day!");
InOut.WriteLn
END guessf.</
<pre>I have chosen a number below 1000; please try to guess it.
Enter your guess : 500
Line 2,741:
=={{header|Nanoquery}}==
<
random = new(Random)
Line 2,777:
end
println "\nThanks for playing."</
=={{header|Nemerle}}==
<
using System.Console;
Line 2,806:
} while (guess != secret)
}
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref symbols nobinary
Line 2,871:
return
</syntaxhighlight>
=={{header|NewLISP}}==
<
; oofoe 2012-01-19
; http://rosettacode.org/wiki/Guess_the_number/With_feedback
Line 2,901:
(println "\nWell guessed! Congratulations!")
(exit)</
Sample output:
Line 2,919:
=={{header|Nim}}==
<
randomize()
Line 2,941:
else: echo " Ye-Haw!!"
echo "Thanks for playing."</
=={{header|NS-HUBASIC}}==
<
20 INPUT "I'M THINKING OF A NUMBER BETWEEN 1 AND 10. WHAT IS IT? ",GUESS
30 IF GUESS>NUMBER THEN PRINT "MY NUMBER IS LOWER THAN THAT.": GOTO 20
40 IF GUESS<NUMBER THEN PRINT "MY NUMBER IS HIGHER THAN THAT.": GOTO 20
50 PRINT "THAT'S THE CORRECT NUMBER."</
=={{header|Objeck}}==
<
bundle Default {
Line 2,985:
}
}
</syntaxhighlight>
=={{header|OCaml}}==
<
try read_int()
with _ ->
Line 3,023:
loop ()
in
loop ()</
Playing the game:
Line 3,056:
=={{header|Octave}}==
<
% Guess a number (with feedback)
% http://rosettacode.org/wiki/Guess_the_number/With_feedback
Line 3,082:
end
end
disp('Well guessed!')</
=={{header|Oforth}}==
<
: guessNumber(a, b)
Line 3,096:
g n == ifTrue: [ "You found it !" .cr return ]
g n < ifTrue: [ "Less" ] else: [ "Greater" ] . "than the target" .cr
again ;</
=={{header|Ol}}==
<syntaxhighlight lang="ol">
(import (otus random!))
Line 3,126:
((= guess number)
(print "Well guessed!")))))
</syntaxhighlight>
=={{header|ooRexx}}==
Line 3,136:
entering ? shows the number we are looking for
This program should, of course, also work with all other Rexxes
<syntaxhighlight lang="oorexx">
/*REXX program that plays the guessing (the number) game. */
low=1 /*lower range for the guessing game.*/
Line 3,193:
ser: say; say '*** error ! ***'; say arg(1); say; return
</syntaxhighlight>
=={{header|PARI/GP}}==
<
a=random(N);
print("guess the number between 0 and "N);
Line 3,210:
);
print("You guessed it correctly")
};</
=={{header|Pascal}}==
Line 3,216:
=={{header|Perl}}==
<
my $prompt = shift;
while (1) {
Line 3,234:
while ($_ = $tgt <=> prompt "Your guess");
print "Correct! You guessed it after $tries tries.\n";</
=={{header|Phix}}==
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Guess_the_number3.exw
Line 3,275:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PHP}}==
<
<?php
Line 3,329:
</body>
</html>
</syntaxhighlight>
=={{header|PicoLisp}}==
{{trans|PureBasic}}
<
(use (Low High Guess)
(until
Line 3,351:
"Your guess is too "
(if (> Number Guess) "low" "high")
"." ) ) ) ) )</
Output:
<pre>: (guessTheNumber)
Line 3,364:
=={{header|Plain English}}==
<
The high number is 100.
Line 3,391:
Convert the string to the number.
If the number is less than the low number, write " Guess can't be lower than " then the low number then "." on the console; repeat.
If the number is greater than the high number, write " Guess can't be higher than " then the high number then "." on the console; repeat.</
{{out}}
<pre>
Line 3,419:
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
function Get-Guess
{
Line 3,465:
Write-Host ("The number was {0} and it took {1} guesses to find it." -f $answer.Number, $answer.Guesses.Count)
</syntaxhighlight>
{{Out}}
<pre>
Line 3,490:
{{works with|SWI-Prolog|6}}
<
play_guess_number.
Line 3,526:
; Guess > N -> writeln('Your guess is too high.')
; Guess =:= N -> writeln("Correct!")
).</
Input in the standard Prolog top level is terminated with a `.`: E.g.,
<
Guess an integer between 1 and 10.
Guess the number: a.
Invalid input.
Guess the number: 3.
Your guess is too low.</
=={{header|PureBasic}}==
<
Repeat
Line 3,558:
PrintN("Your guess is to high.")
EndIf
ForEver</
=={{header|Python}}==
<
inclusive_range = (1, 100)
Line 3,586:
if answer > target: print(" Too high.")
print("\nThanks for playing.")</
'''Sample Game'''
Line 3,623:
=={{header|Quackery}}==
<
cr cr
100 random 1+
Line 3,641:
say "Well done! "
echo say " is correct. " cr
drop ] is guess-the-number ( --> )</
{{out}}
Line 3,675:
This solution works on the assumption that the number to be found is an integer and also assumes that the upper and lower bounds are distinct integers used inclusively. For example, this means that low=4 and high=5 should be a solvable case, but low=high=4 will throw an error. See [[Talk:Guess the number/With feedback|Talk page]] entry dated 1st June 2020.
<
{
boundryErrorCheck(low, high)
Line 3,707:
while(!is.numeric(guess) || as.integer(guess) != guess){guess <- type.convert(readline("That wasn't an integer! Try again "))}
as.integer(guess)
}</
=={{header|Racket}}==
<
(define (guess-number min max)
Line 3,728:
(guess-number 1 100)
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
until 0 < $maxnum < Inf {
say "Oops! The upper boundary should be > 0 and not Inf";
Line 3,755:
}
}
say "Great you guessed right after $count attempts!";</
<pre>Hello, please give me an upper boundary: 10
Line 3,767:
=={{header|Retro}}==
<
over > [ "high" ] [ "low" ] if ;
Line 3,782:
think [ getToken toNumber checkGuess ] while
"You got it!\n" puts ;
</syntaxhighlight>
=={{header|REXX}}==
To make the program more engaging, randomized words for the hint are used.
<
low= 1 /*the lower range for the guessing game*/
high= 100 /* " upper " " " " " */
Line 3,820:
/*stick a fork in it, we're all done. */
if try==1 then say 'Gadzooks!!! You guessed the number right away!'
else say 'Congratulations!, you guessed the number in ' try " tries."</
=={{header|Ring}}==
<
while true
see "Hey There,
Line 3,853:
d = random(e)
if d >= s return d ok
end</
=={{header|Ruby}}==
{{trans|Mirah}}
<
puts "Guess the number between 1 and 10"
Line 3,875:
puts "Please enter an integer."
end
end</
=={{header|Rust}}==
{{libheader|rand}}
<
use std::cmp::Ordering;
use std::io;
Line 3,916:
}
}
}</
<pre>I have chosen my number between 1 and 100. Guess the number!
Please input your guess.
Line 3,952:
=={{header|Scala}}==
<
import java.util.Scanner
Line 3,968:
else if (guessedNumber < randomNumber) println("Your guess is too low!")
else println("You got it!")
} while (guessedNumber != randomNumber)</
=={{header|Scheme}}==
{{works with|Chicken Scheme}}
{{works with|Guile}}
<
(define minimum -5)
(define number (+ (random (- (+ maximum 1) minimum)) minimum))
Line 3,990:
(if (< guess number)
(display "Too low!\n> ")))))
(display "Correct!\n")</
=={{header|Seed7}}==
<
const integer: lower_limit is 0;
Line 4,019:
writeln("You gave up!");
end if;
end func;</
=={{header|Sidef}}==
{{trans|Ruby}}
<
say "Guess the number between 1 and 10";
Line 4,032:
default { say "Too high" }
}
}</
=={{header|Small Basic}}==
<
TextWindow.WriteLine("I just thought of a number between 1 and 10. What is it?")
While guess<>number
Line 4,046:
EndIf
EndWhile
TextWindow.WriteLine("You win!")</
=={{header|Smalltalk}}==
Line 4,056:
To play: run "GuessingGame playFrom: 1 to: 100" on a Workspace (Tools -> Workspace)
<syntaxhighlight lang="smalltalk">
'From Pharo7.0.3 of 12 April 2019 [Build information: Pharo-7.0.3+build.158.sha.0903ade8a6c96633f07e0a7f1baa9a5d48cfdf55 (64 Bit)] on 30 October 2019 at 4:24:17.115807 pm'!
Object subclass: #GuessingGame
Line 4,154:
play! !
</syntaxhighlight>
=={{header|Sparkling}}==
<
let lowerBound = toint(getline());
Line 4,183:
break;
}
}</
=={{header|Swift}}==
<
var found = false
Line 4,208:
println("Good try but the number is less than that!")
}
}</
=={{header|Tcl}}==
<
set to 10
set target [expr {int(rand()*($to-$from+1) + $from)}]
Line 4,230:
break
}
}</
Sample output:
<pre>
Line 4,251:
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT
PRINT "Find the luckynumber (7 tries)!"
Line 4,272:
IF (round==7) PRINT/ERROR "You've lost: luckynumber was: ",luckynumber
ENDLOOP
</syntaxhighlight>
Output:
<pre>
Line 4,299:
{{works with|Public Domain Korn SHell}}
{{works with|Z SHell}}
<
[[ -n $BASH_VERSION ]] && shopt -s extglob
[[ -n $ZSH_VERSION ]] && set -o KSH_GLOB
Line 4,324:
fi
done
}</
Sample run:
Line 4,343:
=={{header|Ursa}}==
{{trans|Python}}
<
set low 0
set high 100
Line 4,372:
end while
out endl "Thanks for playing." endl console</
=={{header|Vala}}==
<
void main(){
const int from = 1;
Line 4,407:
}//while
} // main
</syntaxhighlight>
Shorter but no error checking
<
int guess, x = Random.int_range(1, 10);
stdout.printf("Make a guess (1-10): ");
Line 4,418:
stdout.printf("Got it!\n");
return 0;
}</
=={{header|VBA Excel}}==
The Application.InputBox display a message when input is inappropriate.
<
Dim Nbc&, Nbp&, m&, n&, c&
Line 4,439:
Loop
MsgBox "Well guessed!" & vbCrLf & "You find : " & Nbc & " in " & c & " guesses!"
End Sub</
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Dim max,min,secretnum,numtries,usernum
max=100
Line 4,469:
End If
Loop
</syntaxhighlight>
=={{header|Vlang}}==
{{trans|go}}
<
import rand
import os
Line 4,496:
}
}
}</
=={{header|VTL-2}}==
<
20 L=?
30 ?="Maximum? ";
Line 4,522:
220 ?="Correct!"
230 ?="Tries: ";
240 ?=T</
{{out}}
<pre>Minimum? 10
Line 4,541:
=={{header|Wren}}==
<
import "random" for Random
Line 4,561:
break
}
}</
{{out}}
Line 4,586:
=={{header|XLISP}}==
<
; minimum and maximum, to be supplied by the user
(defun prompt ()
Line 4,611:
(display ". Try to guess it!")
(newline)
(prompt))</
{{out}}
<pre>[1] (guessing-game 19 36)
Line 4,633:
=={{header|XPL0}}==
<
int Lo, Hi, C, Guess, Number;
Line 4,656:
CrLf(0);
until Guess = Number;
]</
Example output:
Line 4,674:
=={{header|zkl}}==
<
while(1){
n:=ask("Num between 1 & 10: ");
Line 4,680:
if(n==r){ println("Well guessed!"); break; }
println((n<r) and "small" or "big");
}</
{{out}}
<pre>
Line 4,697:
=={{header|Zoomscript}}==
For typing:
<
var guess
randnum & random 1 10
Line 4,713:
endif
endwhile
print "Correct number. You win!"</
For importing:
Line 4,720:
=={{header|ZX Spectrum Basic}}==
<
1 LET n=INT (RND*10)+1
2 INPUT "Guess a number that is between 1 and 10: ",g: IF g=n THEN PRINT "That's my number!": STOP
3 IF g<n THEN PRINT "That guess is too low!": GO TO 2
4 IF g>n THEN PRINT "That guess is too high!": GO TO 2</
|