所以我正在编写批处理文件,我创建了一个文件,您可以通过问题选择答案,并将其自动保存到文件中。但我想在将其保存到文件之前制作一些东西,让人们确认他们的选择。简化,我喜欢这样:
Rem Question 1 appearance
:q1
cls
Echo.
Echo Please select your age:
Echo ==================
Echo A) younger than 18
Echo B) 18-30
Echo C) 30-45
Echo D) older than 45
Echo.
Echo.
Rem Question 1 in- and output settings
:q1.2
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose an age of less than 18. & pause & goto q2
if "%INPUT%"=="B" Echo You chose an age of 18-30. & pause & goto q2
if "%INPUT%"=="C" Echo You chose an age of 30-45. & pause & goto q2
if "%INPUT%"=="D" Echo You chose an age of older than 45. & pause & goto q2
Echo Please enter a valid answer!
goto q1.2
Rem question 2 appearance
:q2
Echo Answer: %INPUT% >>Question1answers.txt
cls
Echo.
Echo Please select your favourite colour:
Echo ==========================
Echo A) Blue
Echo B) Red
Echo C) Green
Echo D) Yellow
Echo E) Other
Echo.
Echo.
Rem Question 2 in- and output settings
:q2.1
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose blue.&pause&goto end
if "%INPUT%"=="B" Echo You chose red.&pause&goto end
if "%INPUT%"=="C" Echo You chose green.&pause&goto end
if "%INPUT%"=="D" Echo You chose yellow.&pause&goto end
if "%INPUT%"=="E" Echo You chose something else.&pause&goto end
Echo Please enter a valid answer!
goto q2.1
所以我要求你不回复完整的代码,也许是一小部分,这样我就可以从中学习并把它放在自己身上,你知道吗?谢谢!
编辑:
所以现在我添加了这部分:
:confirmation
cls
Echo Please make sure this is your data:
if "%INPUTT%"=="A" Echo You chose an age of less than 18.
if "%INPUTT%"=="B" Echo You chose an age of 18-30.
if "%INPUTT%"=="C" Echo You chose an age of 30-45.
if "%INPUTT%"=="D" Echo You chose an age of older than 45.
echo.
if "%INPUT%"=="A" Echo You chose blue as your favourite colour.
if "%INPUT%"=="B" Echo You chose red as your favourite colour.
if "%INPUT%"=="C" Echo You chose green as your favourite colour.
if "%INPUT%"=="D" Echo You chose yellow as your favourite colour.
if "%INPUT%"=="E" Echo You chose something else as your favourite colour.
choice /m "Is this your data?" /d Y
if %errorlevel%==1 goto q1
Echo Answer: %INPUTT% >>Question1answers.txt
Echo Answer: %INPUT% >>Question2answers.txt
所以我开始调试,当我来到这个部分时它错了,它让我通过并仍然保存我的输入。它有点忽略了 如果%errorlevel%== 1转到q1 那我现在该怎么办?
答案 0 :(得分:1)
因为你要求一个简短的片段,这应该做你想要的:
set /p "age=Enter your age: "
choice /M "Your age is %age%, correct?"
if %errorlevel%==1 goto :correct
echo false
goto :eof
:correct
echo true