2014-02-10 63 views
0

所以我決定使用一個子程序來改進當前的程序。我把它放在自己的批處理文件中進行測試,並在不影響整個程序的情況下正常工作,並且我得到了它的工作保存了一件事。出於某種原因,每次運行時,都會打印出「失蹤運算符」作爲其第一行。爲什麼我的批處理腳本將第一行打印爲「Missing Operator」?

注意:我知道它是不正確地執行F到C的轉換。我現在正在解決這個問題。

Subroutine as it is working now.

我不知道這是爲什麼,我需要它不打印任何附加行不僅沒有行詮釋他的計劃,但由於成品節目的每個屏幕都有一組號碼它將在任何時候顯示的行和列。整頁上多出一行,它會切斷應顯示的部分屏幕。

這個子程序(和我使用的測試程序)的代碼是:

@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 

回答

4

set /a fer=%random% %% %xsides% + 59 

Sintax錯誤此外,有批量算術沒有小數所以這

set /a cels=%fer1%/1.8 

應該

set /a cels=%fer1% * 10/18 
+0

謝謝!如果我使用 set/a cels =%fer1%* 18/10 適當的數學方法是「%fer1%* 10/18。 –

相關問題