-1

I'm trying to make a money checker for a game, however I keep getting the error: "5 was unexpected at this time."

Code:

:711Beans
title BEANS AAAAAAA
if %money% LSS 5 (
    title No Money?
    cls
    echo Silly, you don't have enough money to buy beans.
    echo Cash Money: $%money%
    pause>nul
    goto 711
)
if %money% GEQ 5 (
    cls
    set /a money=%money%-5
    echo You buy some beans from the 7/11 for 5$
    echo Cash Money: $%money%
    pause>nul
    goto 711
)

So what I've tried is adding: "setlocal ENABLEDDELAYEDEXPANSION" at the top of my batch file and that also didn't work. Could someone explain why this error is occurring and how to fix it? Thanks in advance.

  • 1
    I can't see how you have defined the `%money%` variable, but please have a look at this post on how to use [variables defined using exclamation marks with delayed expansion](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected) – Qwerty May 24 '22 at 19:21
  • 1
    You've enabled delayed expansion but you aren't using it. You need to say `!money!` instead of `%money%`. – SomethingDark May 24 '22 at 20:30
  • @Qwerty I have defined it earlier in the code. And when I add "setlocal enabledelayedexpansion" to my batch file and replace the % with ! it doesn't show the correct amount of money. Where do I put setlocal enabledelayedexpansion?? – Windows_736 May 25 '22 at 21:10

0 Answers0