Very basic guess the number program HELP!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
flemish4
Posts: 2
Joined: 25 Feb 2012 11:49

Very basic guess the number program HELP!

#1 Post by flemish4 » 25 Feb 2012 11:57

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!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Very basic guess the number program HELP!

#2 Post by Squashman » 25 Feb 2012 12:19

Well I can see you have a spelling error. That might help a bit.

aGerman
Expert
Posts: 4713
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Very basic guess the number program HELP!

#3 Post by aGerman » 25 Feb 2012 16:18

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

flemish4
Posts: 2
Joined: 25 Feb 2012 11:49

Re: Very basic guess the number program HELP!

#4 Post by flemish4 » 25 Feb 2012 18:02

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!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Very basic guess the number program HELP!

#5 Post by Squashman » 25 Feb 2012 18:20

No you did not correct all the issues with your original code. Copy and paste aGerman's code he gave you.

Post Reply