Reputation: 11
I'm trying to create a simple number-guessing game with batch. However, I have never been able to use parentheses correctly. The code is:
@echo off
::This is a game that has you guess a random number.
Title Random Number Game
set number=%random%
:guess
set /p guess1= Guess the number I'm thinking of!
if %guess1%LSS%number% (
echo Higher!
goto guess
)
if %guess1%GTR%number% (
echo Lower!
goto guess
)
echo You got it! Awesome Job!
Whether my guess is higher or lower than the number, after entering it, cmd returns, "( was not expected at this time." How do I fix this?
Upvotes: 0
Views: 1720
Reputation: 130849
You almost had everything correct. You just need a space around the comparison operators
if %guess1% LSS %number% (
echo Higher!
goto guess
)
if %guess1% GTR %number% (
echo Lower!
goto guess
)
Upvotes: 2