2016-11-11 138 views
0

有运行我的批处理文件中的困难时期。
我相信这与我的if语句有关,它不会通过。
我总是以“如果在这个时候意外”结束。
请任何帮助非常感谢Windows批处理标签循环

: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

我想,以限定的情况下的默认用户只需按下_enter_,如'设置“firstNum = 0”'和'设置“secondNum = 0”''之前设置/ P'插入标准'set'命令, 分别;那么我会从'if'比较中删除引号,并用'EQU'替换运算符'=='以便进行数字比较而不是字符串比较(如'if%secondNum%EQU 0');最后,我会缩进一对括号中的所有命令以提高可读性... – aschipfl

回答

0
) if "%secondNum%"=="0" (

应该

) 
if "%secondNum%"=="0" (

)终止先前的if声明。 cmd看到该行的其余部分的东西,不应该遵循)


(后 - 缺少操作数...)

批次是在SET声明空格敏感。 SET FLAG = N一个名为“FLAG 空间”变量设置到“空间 N”

因此,一个值,你set /p "firstnum = ...设置一个名为“firstNum 空间”变量 - 这是不一样的变量“ firstNum”

由于既不firstnum也不secondnum包含值,cmd看到

集合/的商=/

失去了=的两侧的空间在你的set语句。

+0

我做了更改后,我现在收到的错误是“缺少操作数除以=” –