Sunday, 25 August 2013

Compare two numbers in a batch file

Compare two numbers in a batch file

I searched this site for my question, but i didn't find where is my
problem. ( Sorry for my bad english )
The system gives a random number for the player and for the computer, from
2 to 12. This has 3 parts, if X bigger than Y, if X lesser than Y, when X
is same as Y. When i start the .bat, it works great, i choose Play Game, i
enter the Bet, ( 20 for example ) , but when i start this process, the
window closes, and i cant read what did it wrote ( because i can see some
flashing text, i have seen 'Your' and 'syntax', but it disappears very
fast.
Im really sure it worked, because when i delete the 3 if if if things, it
shows my money, bet, stats and everything, and i can even decrease or
increase it with 'cheats' i wrote.
So, here is it:
set /p setbet=Please type a number to select bet:
if "%setbet%"=="1" set bet=20
if "%setbet%"=="2" set bet=50
if "%setbet%"=="3" set bet=100
if "%setbet%"=="4" set bet=150
if "%setbet%"=="5" set bet=200
if "%setbet%"=="6" set bet=250
if "%setbet%"=="7" set bet=300
echo.
echo Your bet is %bet%.
echo.
pause
cls
set /a money-=bet
set /a playernum=%random% %%12 +2
set /a enemynum=%random% %%12 +2
echo.
echo You roll: %playernum%
echo Enemy rolls: %enemynum%
echo.
if %playernum% LSS %enemynum%
(
echo Enemy wins. Please try again.
echo Your current money is %money%.
echo You lost %bet% money.
echo.
pause
goto INTRO
)
if %enemynum% LSS %playernum%
(
set /a money+=bet*2
echo You win.
echo Your current money is %money%.
echo You won %bet% money.
echo.
pause
goto INTRO
)
if %enemynum% EQU %playernum%
(
set /a money+=bet
echo It's a tie.
echo You won the bet (%bet%), but your money didn't changed.
echo Your money is now %money%.
echo.
pause
goto INTRO
Thank you!

No comments:

Post a Comment