Page 1 of 1

Very basic guess the number program HELP!

Posted: 25 Feb 2012 11:57
by flemish4
I'm just starting to learn a few new languages and I was trying to make a batch program that chose a random number with %random% then told you higher or lower until you guessed correctly...

So far I have this:


@echo off
set Num=%random%
set /a Count=0
echo Try to guess the number!

:Top
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Highter
if %udefine%==%num% Goto Win

:Lower
echo Too high try LOWER
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Highter
if %udefine%==%num% Goto Win

:Higher
Too low try HIGHER
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Highter
if %udefine%==%num% Goto Win

:Win
echo Well done you win!
echo The winning number was %Num%!
echo And it took you %count% tries!
Pause


It doesn't work :( :(

Help much appreciated!

Re: Very basic guess the number program HELP!

Posted: 25 Feb 2012 12:19
by Squashman
Well I can see you have a spelling error. That might help a bit.

Re: Very basic guess the number program HELP!

Posted: 25 Feb 2012 16:18
by aGerman
set /a %count%+1

if %udefine% LSS %Num% GOTO Highter

:Higher
Too low try HIGHER (missing ECHO)

Code: Select all

@echo off &setlocal
set Num=%random%
set /a Count=0
echo Try to guess the number!

:Top
set /a count+=1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Higher
if %udefine%==%num% Goto Win

:Lower
echo Too high try LOWER
set /a count+=1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Higher
if %udefine%==%num% Goto Win

:Higher
echo Too low try HIGHER
set /a count+=1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Higher
if %udefine%==%num% Goto Win

:Win
echo Well done you win!
echo The winning number was %Num%!
echo And it took you %count% tries!
Pause


Regards
aGerman

Re: Very basic guess the number program HELP!

Posted: 25 Feb 2012 18:02
by flemish4
I think I have corrected the mistakes! :P

Still not working :((

@echo off
set Num=%random%
set /a %Count%=0
echo Try to guess the number!

:Top
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Highter
if %udefine%==%num% Goto Win

:Lower
echo Too high try LOWER
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Higher
if %udefine%==%num% Goto Win

:Higher
echo Too low try HIGHER
set /a %count%+1
set /p udefine=
if %udefine% GTR %Num% GOTO Lower
if %udefine% LSS %Num% GOTO Highter
if %udefine%==%num% Goto Win

:Win
echo Well done you win!
echo The winning number was %Num%!
echo And it took you %count% tries!
Pause


Thanks for the help!

Re: Very basic guess the number program HELP!

Posted: 25 Feb 2012 18:20
by Squashman
No you did not correct all the issues with your original code. Copy and paste aGerman's code he gave you.