Author Options:

My batch file won't work! Answered

I was working on a puzzle batch file. Everything works except for the end, where it quits for no reason. Here's the code: @echo off
set puzzle1=%random%
set puzzle2=%random%
set puzzle3=%random%
echo I will make three files.
echo Each of them will be a piece of the puzzle.
echo Are you ready?
echo Begin.
echo %puzzle1% >> 1.txt
echo %puzzle2% >> 2.txt
echo %puzzle3% >> 3.txt
set answer=
set /p answer=Answer:
if '%answer%'=='%puzzle1% %puzzle2% %puzzle3%' goto b
if not '%answer%'=='%puzzle1% %puzzle2% %puzzle3%' goto a
echo I knew you could do it.
FOR %%A IN (*.txt*) DO DEL %%A
pause >nul

2 Replies

BangBang1337 (author)2015-02-22


Now it works perfectly!

Select as Best AnswerUndo Best Answer

g-one (author)2015-02-18

The apostrophes have no special meaning in an IF comparison but the spaces split the second operand into three parts. You can avoid that if you enclose both operands into quotation marks instead.

Albeit I'm not really certain if that is what you actually want to do. The user has to input all three random numbers sparated with spaces. Only one or two right guesses would never match though.

Select as Best AnswerUndo Best Answer