所以我正在批量做一点“猜猜游戏”。 (你必须猜测1-20的数字)
这是代码的一部分:
cls
set /a guessnum = %random% %%20 +1 //Generates Number from 1-20
echo A Number Between 1 - 20
set /p "guess"=">>>Guess!"
*<----- The Code Crashes Right Here*
if %guess% gtr %guessnum% echo The Number is smaller
if %guess% lss %guessnum% echo The Number is bigger
if %guess% == %guessnum% goto righteasy
有人可以帮助我吗?
答案 0 :(得分:1)
批量//Generates Number from 1-20
中的结尾注释无效
请改用&rem Generates Number from 1-20
。
set /a guessnum = %random% %%20 +1 //Generates Number from 1-20
为两个分裂标志返回missing operand error
因此guessnum
未被定义,并且通过不正确的引用,输入变量被命名为guess"
而不是guess
if %guess% gtr %guessnum% echo The Number is smaller
评估为:
if gtr echo The Number is smaller
返回
echo was unexpected at this time.
这批:
@echo off
cls
set cnt=0
set /a guessnum=%random% %%20 +1 &rem Generates Number from 1-20
echo A Number Between 1 - 20
:loop
set /p "guess=>>>Guess!"
set /a cnt+=1
rem *<----- The Code Crashes Right Here*
if %guess% gtr %guessnum% echo The Number is smaller&goto :loop
if %guess% lss %guessnum% echo The Number is bigger&goto :loop
Echo You got it right with %cnt% guess(es)
将生成此示例输出:
A Number Between 1 - 20
>>>Guess!10
The Number is smaller
>>>Guess!5
The Number is smaller
>>>Guess!3
You got it right with 3 guess(es)