我一直在使用此代码时遇到问题。请看看,告诉我有什么问题,以便我可以解决它。此代码将成为xprize竞赛的一部分!
echo [Math]
echo.
echo.
echo.
echo Question 1
echo.
echo.
echo.
echo If Mary goes to the market and buys three
echo bananas for two dollars each, how much
echo did she spend altogether?
echo.
echo.
echo (A) $3
echo (B) $6
echo (C) $5
echo (D) $1
echo.
echo.
echo.
set /p ANSWER01=Answer:
cls
goto results
:results
set /a "COUNTER=0"
这是我无法弄清楚的: 我不知道如何在if语句中更改变量的值
if %ANSWER01%==b(
set /a "COUNTER=COUNTER+1"
)
echo %COUNTER%
pause
答案 0 :(得分:1)
您应该使用以下选项命令:
Choice /c abcd /m "Answer: "
set ANSWER01=%errorlevel%
也适用于你的if语句,只需这样做:
if %ANSWER01% equ 2 set /a "COUNTER=COUNTER+1"
这会更容易也更好。
注意: equ 2
如果您使用choice
命令
答案 1 :(得分:0)
b
和(
AAMOI,if /i
会使匹配不区分大小写。
答案 2 :(得分:0)
嗨,确实需要启用延迟扩展选项,并为句子括号提供一个空格:
您的代码类似于:
set /a counter=0
setlocal ENABLEDELAYEDEXPANSION
echo [Math]
echo.
echo.
echo.
echo Question 1
echo.
echo.
echo.
echo If Mary goes to the market and buys three
echo bananas for two dollars each, how much
echo did she spend altogether?
echo.
echo.
echo (A) $3
echo (B) $6
echo (C) $5
echo (D) $1
echo.
echo.
echo.
set /p ANSWER01=Answer:
cls
goto results
:results
if %ANSWER01%==b (
set /a counter=counter+1
)
echo %counter%
pause
endlocal