0

这段代码我一直有问题。请看一下并告诉我出了什么问题,以便我修复它。此代码将成为 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
4

3 回答 3

1

您应该将选择命令与:

Choice /c abcd /m "Answer: "
set ANSWER01=%errorlevel%

同样对于您的 if 语句,只需这样做:

if %ANSWER01% equ 2 set /a "COUNTER=COUNTER+1"

那会更容易更好。

注意:如果equ 2你使用choice命令

于 2013-07-18T03:26:40.110 回答
0

嗨,确实需要启用延迟扩展选项并在括号中为 if 语句留一个空格:

您的代码类似于:

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
于 2013-07-18T03:31:09.117 回答
0

你需要在 theb和 the之间留一个空格(

AAMOI,if /i将使匹配不区分大小写。

于 2013-07-18T03:21:40.710 回答