所以我写了一个有趣的批处理文件,我有一个多项选择语句,所以我有这样的语句:
@echo off
title John's apples
echo.
echo John got 3 apples, he gives 1 away. How many does he have then?
echo (Please answer with ONE capital letter, or type Exit to exit.)
echo =============
echo.
echo A) 2.5
echo B) 3.459475945
echo C) 2
echo D) 1
echo Exit
echo.
:answer
set /p ans=Your Answer:
if "%
if "%ans%"=="a" Echo Please answer with a capital letter!&set /p ans=Your Answer:
if "%ans%"=="b" Echo Please answer with a capital letter!&set /p ans=Your Answer:
if "%ans%"=="c" Echo Please answer with a capital letter!&set /p ans=Your Answer:
if "%ans%"=="d" Echo Please answer with a capital letter!&set /p ans=Your Answer:
if "%ans%"=="A" Echo Wrong! The answer was 2.
if "%ans%"=="B" Echo Wrong! The answer was 2.
if "%ans%"=="C" Echo Right! Good job! The answer was 2.
if "%ans%"=="D" Echo Wrong! The answer was 2.
if "%ans%"=="Exit" exit
Pause
Exit所以现在我想知道,如果有人输入了错误的答案(因为你必须输入一个大写字母,否则它将不起作用),它什么也不会说。所以我想知道我是怎么做的:如果A,B,C,D不是输入,打印“请输入有效的答案!”
有人能帮上忙吗?这可能已经被问到了,对不起,that...there可能是脚本中的一些随机的东西,因为我正在测试一些东西。
发布于 2017-07-17 11:33:01
我可能做了一点修改,但这个效果要好得多:
@echo off
color 0a
cls
:game
title John's apples
cls
echo John got 3 apples, he gives 1 away. How many does he have then?
echo (Please answer with ONE capital letter)
echo ===============================================================
echo A) 2.5
echo B) 3.459475945
echo C) 2
echo D) 1
echo E) Exit
set /p ans=
if %ans%== a goto capital
if %ans%== A goto wrong
if %ans%== b goto capital
if %ans%== B goto wrong
if %ans%== c goto capital
if %ans%== C goto correct
if %ans%== d goto capital
if %ans%== D goto wrong
if %ans%== e exit
:wrong
Echo Wrong! The Answer was 2.
pause
exit
:capital
echo Please answer with a capital letter!
pause
goto game
:correct
echo Right! Good job! The answer was 2!
pause
exithttps://stackoverflow.com/questions/34722849
复制相似问题