2

I am just writing a silly little program, but the problem I'm having seems quite generic.

Here is the part of the code that is causing me problems:

Warning: the code opens a google search.

set /a c=0
:Longcat
CLS
Echo.
ECHO *****************************************************************
ECHO.
echo            How LONG is this cat?
echo.
echo *****************************************************************
Echo.
timeout 5 >nul
If %c%==0 start https://www.google.com/search?q=LongCat
set /a c=%c%+1
If %c%==10 goto incorrect
Set /p cat=
If %cat%==long goto correct
goto Longcat
:correct
Echo correct
pause
Goto geometric
:incorrect
echo incorrect
pause
goto geometric

When I enter single word responses for /p cat=, like big or tall, the program works fine (continues to GOTO LONGCAT).

But as soon as I use a 2 word answer, like very big, I get an error:

big==long was unexpected at this time.

Does anyone have an explanation or a fix for this?

1 Answer 1

4

Does anyone have an explanation or a fix for this?

If %cat%==long goto correct

If you enter very big then the above command expands to:

If very big==long goto correct

which is a syntax error:

big==long was unexpected at this time.

You need to add quotes ("s) to your if comparison to compare multi word inputs:

If "%cat%"=="long" goto correct

Now, if you enter very big then the above command expands to:

If "very big"=="long" goto correct

which is a valid command.


Further Reading

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .