1

I have created a simple riddles program on CMD using a Batch File. I would like it so that answers such as one can be answered as 1 aswell. So far I have this:

:Riddle_1
cls
echo.
echo I shake the earth with booming thunder
echo fell forests whole and homes complete.
echo I influence ships, topple kings
echo sweep down swift yet remain unseen.
echo.
set /p answer=What am I?
if %answer%==wind (goto Riddle_2) else (goto Riddle_1)

When I try:

if %answer%==wind (goto Riddle_2) else (goto Riddle_1)
if %answer%==Wind (goto Riddle_2) else (goto Riddle_1)

It ignores the second command altogether other variations do this or they will ignore the else command and make it go to the next question when the answer is wrong.

Is there anyway to fix this??

  • This requires nothing more than an IF that ignores case, and foxidrive demonstrates how. If you truly want to match multiple values, like "wind" or "gust", then see [IF… OR IF… in a windows batch file](http://stackoverflow.com/q/8438511/1012053) – dbenham Jun 27 '14 at 17:10

2 Answers2

2

The /i makes the compare case insensitive and the double quotes make it more robust in various ways.

if /i "%answer%"=="wind" (goto Riddle_2) else (goto Riddle_1)
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0

You could do it this way

set res=false
if %answer%==wind set res=true
if %answer%==Wind set res=true
if "%res%"=="true" (
    goto Riddle_2
)
else
(
   goto Riddle_1
)
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304