我正在批量创建一个简单的随机数猜测器,但我的代码中出现错误,并且不知道它是什么请求帮助。这是代码:
@echo off
title Number Guesser
:menu
echo ------------------
echo Number Guesser
echo ------------------
echo 1. Easy
echo 2. Medium
echo 3. Hard
echo 4. Exit
set /p dif=Select difficulty number:
if %dif% == 1 goto easygen
if %dif% == 2 goto medgen
if %dif% == 3 goto hardgen
if %dif% == 4 exit
goto menu
:easygen
set /a num=%random%
if %num% gtr 20 goto gen
cls
goto play
:medgen
set /a num=%random%
if %num% gtr 50 goto gen
cls
goto play
:hardgen
set /a num=%random%
if %num% gtr 100 goto gen
cls
goto play
:play
set /p guess=Guess:
if %guess% == %num% goto win
if %guess% gtr %num% echo Lower!
if %guess% lss %num% echo Higher!
:win
cls
echo Well Done
echo 1. Play again!
echo 2. Quit
set /p cmd=What do you want to do:
if %cmd% == 1 goto menu
if %cmd% == 2 exit
一旦我选择了难度,我就会得到错误(dif)我不知道什么是不行的。它刚关闭。
答案 0 :(得分:0)
如果您打开cmd然后导航到该文件并运行它,而不是双击批处理文件,您将看到错误。
The system cannot find the batch label specified - gen
与其他评论者一样,您没有定义:gen
。它显示goto gen
,但gen
不存在,因此它会变得怪异并关闭。