所以我决定使用子程序来改进我当前的程序。我把它放在自己的批处理文件中进行测试,让它正常运行而不会搞砸我的整个程序,除了一件事我还能让它工作。出于某种原因,每次运行时,它都会打印“Missing Operator”作为其第一行。
注意:我知道它正在错误地执行F到C转换。我现在正在解决这个问题。
我不知道为什么会这样,我需要它不打印任何额外的行,不仅没有程序中的行,而且因为完成的程序的每个屏幕都有一定数量的行和列,它将在任何时候显示。在整页上增加一行,它将切断应显示的部分屏幕。
此子程序的代码(以及我用来测试它的程序)是:
@echo off
:1
cls
call :ferDesc
echo.
pause
goto 1
:ferDesc
echo off
set /a xsides=54
set /a fer=%random%%%xsides+59
set /a fer1=%fer%-32
set /a cels=%fer1%/1.8
if %fer% leq -40 goto td1
if %fer% leq -30 goto td2
if %fer% leq -20 goto td3
if %fer% leq -10 goto td4
if %fer% leq 0 goto td5
if %fer% leq 10 goto td6
if %fer% leq 20 goto td7
if %fer% leq 30 goto td8
if %fer% leq 40 goto td9
if %fer% leq 50 goto td10
if %fer% leq 60 goto td11
if %fer% leq 70 goto td12
if %fer% leq 80 goto td13
if %fer% leq 90 goto td14
if %fer% leq 100 goto td15
if %fer% leq 110 goto td16
if %fer% leq 120 goto td17
if %fer% leq 130 goto td18
if %fer% geq 131 goto td19
:td1
set td=polar
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td2
set td=artic
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td3
set td=bitterly cold
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td4
set td=very cold
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td5
set td=cold
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td6
set td=wintery
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td7
set td=icey
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td8
set td=frosty
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td9
set td=chilly
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td10
set td=brisk
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td11
set td=cool
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td12
set td=pleasent
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td13
set td=warm
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td14
set td=balmy
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td15
set td=sweaty
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td16
set td=stweltering
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td17
set td=feaverishly hot
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td18
set td=baking
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
:td19
set td=deadly hot
echo It is a %td% day.
echo (%fer% F - %cels% C)
goto :eof
答案 0 :(得分:4)
中的语法错误
set /a fer=%random% %% %xsides% + 59
此外,批处理算术中没有小数,所以
set /a cels=%fer1%/1.8
应该是
set /a cels=%fer1% * 10 / 18
答案 1 :(得分:1)
我在遗失的操作符http://forums.techguy.org/software-development/885945-missing-operator-batch-script.html上发现了这篇文章。也许这会有所帮助。