很难运行我的批处理文件
我认为它与我的if语句有关,它不会落空。
我总是最终得到“如果此时出乎意料的话”
请任何帮助表示感谢
:firstNumber
set /p "firstNum = Enter the first number (other than 22) "
if "%firstNum%"=="22" (
goto :end
) else (
goto :secondNumber
)
:secondNumber
set /p "secondNum = Enter the second number (other than 22 and 0) "
if "%secondNum%"=="22" (
goto :end
) if "%secondNum%"=="0" (
goto :errorNumber
) else (
goto :command
)
:errorNumber
echo You cannot divide by 0
goto :secondNumber
:command
set /a quotient=%firstNum% / %secondNum%
echo "%firstNum% divided by %secondNum% = !quotient!
:end
答案 0 :(得分:0)
) if "%secondNum%"=="0" (
应该是
)
if "%secondNum%"=="0" (
)
终止上一个if
语句。 cmd
将该行的其余部分视为不应遵循)
(稍后 - 缺少操作数...)
批处理对SET
语句中的空格敏感。 SET FLAG = N
将名为“FLAG Space ”的变量设置为值“ Space N”
因此,您的set /p "firstnum = ...
设置了一个名为“firstNum Space ”的变量 - 这与变量“firstNum”
由于firstnum
和secondnum
都不包含值,cmd
会看到
设置/商= /
丢失=
语句中set
两侧的空格。