Guess the number/With feedback (player): Difference between revisions
Content added Content deleted
(Added Algol 68) |
|||
Line 188: | Line 188: | ||
PRINT "Goodbye." |
PRINT "Goodbye." |
||
END</lang> |
END</lang> |
||
=={{header|Batch File}}== |
|||
<lang dos> |
|||
@echo off |
|||
:: Player is prompted to give a number between %min% and %max%. If the input is out of those limits they are prompted to choose again |
|||
:choose |
|||
set min=0 |
|||
set max=100 |
|||
set /p "number=Choose a number [%min%-%max%]: " |
|||
if %number% gtr %max% goto choose |
|||
if %number% lss %min% goto choose |
|||
set attempts=0 |
|||
:: Loops the guessing process until completed |
|||
:comp |
|||
set /a attempts+=1 |
|||
set /a guess=(%max%-%min%)/2+%min% |
|||
choice /c "HLE" /n /m "Guess: %guess% - [H]igher, [L]ower or [E]qual" |
|||
if errorlevel 3 goto end |
|||
if errorlevel 2 ( |
|||
set max=%guess% |
|||
goto comp |
|||
) |
|||
if errorlevel 1 ( |
|||
set min=%guess% |
|||
goto comp |
|||
) |
|||
:end |
|||
echo Guesses: %attempts% |
|||
pause>nul |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Choose a number [0-100]: 42 |
|||
Guess: 50 - [H]igher, [L]ower or [E]qual L |
|||
Guess: 25 - [H]igher, [L]ower or [E]qual H |
|||
Guess: 37 - [H]igher, [L]ower or [E]qual H |
|||
Guess: 43 - [H]igher, [L]ower or [E]qual L |
|||
Guess: 40 - [H]igher, [L]ower or [E]qual H |
|||
Guess: 41 - [H]igher, [L]ower or [E]qual H |
|||
Guess: 42 - [H]igher, [L]ower or [E]qual E |
|||
Guesses: 7 |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |