0

我正在尝试用批处理创建一个简单的猜数游戏。但是,我从来没有能够正确使用括号。代码是:

@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!

无论我的猜测是高于还是低于数字,输入后,cmd返回,“(此时不是预期的。”我该如何解决这个问题?

4

1 回答 1

2

你几乎把一切都说对了。您只需要在比较运算符周围留一个空格

if %guess1% LSS %number% (
  echo Higher!
  goto guess
)
if %guess1% GTR %number% (
  echo Lower!
  goto guess
)
于 2013-01-29T00:23:30.353 回答