我的批处理文件中的某处出现重复错误

问题描述 投票:2回答:1

我一直试图为过去一小时的中国算盘制作一个可视化工具,为此我需要隔离每一个答案,但是当我尝试这样做时,它会以一种看似毫无意义的模式重复一些数字。例如,当我插入12344 + 1时,它给了我123345455作为最终回声。我已经挣扎了很长一段时间并且会喜欢一些帮助,我仍然是批量的初学者,所以我真的不知道为什么会这样。

附:对不起,就像我说的,我是新的

    @echo off
    SET a1=O
    SET a2=O
    SET a3=O
    SET a4=O
    SET a5=O
    SET b1=I
    SET b2=I
    SET b3=I
    SET b4=I
    SET b5=I
    SET c1=I
    SET c2=I
    SET c3=I
    SET c4=I
    set c5=I
    set d1=O
    set d2=O
    set d3=O
    set d4=O
    set d5=O
    set e1=O
    set e2=O
    set e3=O
    set e4=O
    set e5=O
    set f1=O
    set f2=O
    set f3=O
    set f4=O
    set f5=O
    set g1=O
    set g2=O
    set g3=O
    set g4=O
    set g5=O
    :beginning
    echo.
    echo Welcome to the virtual Abacus.
    echo.
    echo I am only a visualization and do not compute in the same way as an abacus.
    echo.
    echo Please be kind, as I can only handle single operator equations,
    echo and keep the answers to below 100,000 too please.
    echo ---------
    echo %a1% %a2% %a3% %a4% %a5% 
    echo %b1% %b2% %b3% %b4% %b5% 
    echo ---------
    echo %c1% %c2% %c3% %c4% %c5% 
    echo %d1% %d2% %d3% %d4% %d5% 
    echo %e1% %e2% %e3% %e4% %e5% 
    echo %f1% %f2% %f3% %f4% %f5% 
    echo %g1% %g2% %g3% %g4% %g5% 
    echo ---------
    set /p Equation=What is your question?
    set /a result=%Equation%
    set Res1=%result:~0,1%
    set Res2=%result:~1,2%
    set Res3=%result:~2,3%
    set Res4=%result:~3,4%
    set Res5=%result:~4,5%
    echo %Res1%%Res2%%Res3%%Res4%%Res5%
    pause
batch-file cmd
1个回答
0
投票

你的“问题”有几个缺点和困惑点。标题没有意义,整个算盘可视化代码的发布与问题没有关系,这只是一个子串问题(不是“重复错误”)。你应该学会自己发现问题并发布更简洁明了的问题......

如果您发布不相关的代码,您可能会获得无关的“答案”,如下所示:

@echo off
setlocal EnableDelayedExpansion

set "rods=13"
cls
echo/
echo Visualization of a Japanese Soroban abacus
rem https://en.wikipedia.org/wiki/Soroban

:loop
echo/
set "number="
set /P "number=Enter a number: "
echo/
if not defined number goto :EOF

set "number= %number%"
for /L %%j in (0,1,7) do set "row%%j="
set "line="
for /L %%i in (%rods%,-1,1) do (
   set "line=!line!--"
   set "row7=!row7! !number:~-%%i,1!"
)

for /L %%i in (%rods%,-1,1) do (
   set /A "digit=!number:~-%%i,1!" 2>NUL
   if !digit! geq 5 (
      set "row6=!row6! |"
      set "row5=!row5! O"
      set /A digit-=5
   ) else (
      set "row6=!row6! O"
      set "row5=!row5! |"
   )
   for /L %%j in (0,1,4) do (
      if !digit! equ %%j (
         set "row%%j=!row%%j! |"
      ) else (
         set "row%%j=!row%%j! O"
      )
   )
)

echo %row7%
echo %line%
for %%j in (6,5) do echo !row%%j!
echo %line%
for /L %%j in (0,1,4) do echo !row%%j!
echo %line%
echo/
goto loop
© www.soinside.com 2019 - 2024. All rights reserved.