我不确定预期输出是什么" 0 5 25 100"。
我得到的输出是" 20 3 15 60":
http://hastebin.com/tibirakoni.dos
@echo off
setlocal EnableDelayedExpansion
cls
:vars
set numbercheck=50
set number2=0
set number3=0
set number4=0
:calc
for %%a in (0, 1, 100) do (
if !numbercheck GEQ 10 (
set /a numbercheck= !numbercheck! - 10
set /a number2= !number2! +1
set /a number3= !number3! +5
set /a number4= !number4! +20
)
)
goto echo
:echo
echo !numbercheck!
echo !number2!
echo !number3!
echo !number4!
pause
答案 0 :(得分:2)
0 5 25 100
我得到的输出是
20 3 15 60
...
for %%a in (0, 1, 100) do ( if !numbercheck GEQ 10 (
...
上述代码中有两个错误:
/l
命令中缺少for
,应该是:
for /l %%a in (0, 1, 100) do (
如果没有/l
,for
循环将返回0,1,1并且仅循环3次。使用/l
for
循环将返回1,2,3,...,100
!
命令中缺少if
,应该是:
if !numbercheck! GEQ 10 (
更正了批处理文件:
@echo off
setlocal EnableDelayedExpansion
cls
:vars
set numbercheck=50
set number2=0
set number3=0
set number4=0
:calc
for /l %%a in (0, 1, 100) do (
if !numbercheck! GEQ 10 (
set /a numbercheck= !numbercheck! - 10
set /a number2= !number2! +1
set /a number3= !number3! +5
set /a number4= !number4! +20
)
)
goto echo
:echo
echo !numbercheck!
echo !number2!
echo !number3!
echo !number4!
pause
示例输出:
0
5
25
100
Press any key to continue . . .