Woops, I messed up. You need "set /a" in there too in front of any variables (ie the noLoGuesses and LG[]
Also, arrays use what are known as array operators, "[ ]" to allocate memory based on the number inside the brackets.
ie: Array[10] will declare 10 blocks of memory depending on the type of variable it is (I am unsure how Windows batch scripting handles this though)
So, you're going to need to do something like this at the beginning of your program:
set /a LG[1000];
set /a HG[1000];
That will set 1000 blocks of memory aside for your arrays. Also I notice you changed your second if statement to also use LSS instead of GTR, and you're incrementing noLoGuesses in your greater than if statement.
here's what I have. The only thing missing is the ability to output all numbers guessed higher and lower than the random value:
EDIT! I think I've been misunderstanding you.. Now I don't think you'll need the arrays but it's always good practice!
You can take out the arrays and get your desired results. All the arrays are for are to store values you guessed. ie if you guessed 13, the array will store 13 and output 13 (along with all the other numbers you guessed) at the end of the program.
Also, arrays use what are known as array operators, "[ ]" to allocate memory based on the number inside the brackets.
ie: Array[10] will declare 10 blocks of memory depending on the type of variable it is (I am unsure how Windows batch scripting handles this though)
So, you're going to need to do something like this at the beginning of your program:
set /a LG[1000];
set /a HG[1000];
That will set 1000 blocks of memory aside for your arrays. Also I notice you changed your second if statement to also use LSS instead of GTR, and you're incrementing noLoGuesses in your greater than if statement.
here's what I have. The only thing missing is the ability to output all numbers guessed higher and lower than the random value:
Code:
@ECHO off
COLOR 0E
CLS
SET RandomNo=%random%
SET /a NoGuesses = 0
set /a NoLoGuesses = 0
set /a NoHiGuesses = 0
set /a LG[1000];
set /a HG[1000];
TITLE = T H E G U E S S A N U M B E R G A M E - %RandomNo%
ECHO.
ECHO.
ECHO.
ECHO.
ECHO W E L C O M E T O T H E ...........
ECHO.
ECHO.
ECHO.
ECHO.
ECHO GGGG U U EEE SSSS SSSS AA N N U U M M BBB EEE RRR
ECHO G G U U E S S A A NN N U U MM MM B B E R R
ECHO G U U E SSS SSS AAAA N N N U U M M M M B B E RRR
ECHO G GG U U EEE SSS SSS A A N N N U U M M M BBB EEE RR
ECHO G G U U E S S A A N NN U U M M B B E R R
ECHO GGGG UU EEE SSSS SSSS A A N N UU M M BBB EEE R R
ECHO.
ECHO.
ECHO G A M E !!!
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
PAUSE
:BEGINLOOP
CLS
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
SET /p UserNumber=Please type your guess:
SET /a NoGuesses += 1
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
IF %UserNumber% LSS %RandomNo% (
set /a LG[NoLoGuesses] = %UserNumber%
set /a NoLoGuesses += 1
ECHO.
ECHO Your guess was too low. Try again.
ECHO.
ECHO.
PAUSE
GOTO :BEGINLOOP
)
IF %UserNumber% GTR %RandomNo% (
set /a HG[NoHiGuesses] = %UserNumber%
set /a NoHiGuesses += 1
ECHO.
ECHO Your guess was too low. Try again.
ECHO.
ECHO.
PAUSE
GOTO :BEGINLOOP
)
CLS
COLOR E0
ECHO.
ECHO * * * * * * * * * * * *
ECHO.
ECHO Congratulations! You guessed it.
ECHO.
ECHO The number was %UserNumber%
ECHO You guessed it in %NoGuesses% guesses
ECHO low guesses %NoLoguesses%
ECHO high guesses %NoHiguesses%
ECHO.
ECHO * * * * * * * * * * * *
ECHO.
PAUSE
EDIT! I think I've been misunderstanding you.. Now I don't think you'll need the arrays but it's always good practice!
You can take out the arrays and get your desired results. All the arrays are for are to store values you guessed. ie if you guessed 13, the array will store 13 and output 13 (along with all the other numbers you guessed) at the end of the program.
Last edited: