所以,我在批处理文件中有一个集合/p。用户要继续操作,必须键入"2“。我似乎在任何地方都找不到我的问题。
@echo off
echo "What is 1+1"
set /p oneplusone=Type Answer Here:
if %oneplusone%==2 goto correct
if %oneplusone% neq 2 goto incorrect
:correct
cls
echo Correct!
pause
goto youranswer
:incorrect
cls
echo Wrong.
pause
goto youranswer
:youranswer
cls
echo You answered: %oneplusone%现在,如果用户键入一个没有空格的数字/单词,那么一切都会正常进行,它会显示出您想要的答案。
但是,如果使用空格键入类似于"hi“的内容,批处理文件就会立即关闭。只有当答案需要是一个数字时,才会出现这种情况,而您需要键入涉及一个空格的内容。
有什么帮助吗?
提前谢谢。
发布于 2015-11-23 16:38:03
您可以使用以下方法检查您的答案是否是一个数字:
set /a test=%oneplusone%*1
if %test%==0 goto notValid再加上另一个标签,让你的代码
@echo off
echo "What is 1+1"
set /p oneplusone=Type Answer Here:
set /a test=%oneplusone%*1
if %test%==0 goto notValid
if %oneplusone%==2 goto correct
if %oneplusone% neq 2 goto incorrect
:correct
cls
echo Correct!
pause
goto youranswer
:incorrect
cls
echo Wrong.
pause
goto youranswer
:notValid
cls
echo Your input is not valid
pause
goto youranswer
:youranswer
cls
echo You answered: %oneplusone%https://stackoverflow.com/questions/33875828
复制相似问题