CMD算术错误

时间:2016-10-29 02:48:49

标签: batch-file

我是编程新手,只是尝试在游戏中为交易路线制作计算器。然而,命令echo %tot_bal_fou% credits in return.的输出始终是sesell

的值
echo.
echo.
echo What is your total balance?
set /p intbal=
cls  
echo What is the cost of the  product in the first station?
set /p  ficost=
cls
echo What is the product's selling price in the first station?
set /p fisell=
cls
echo What is the cost of the product in the second station?
set /p secost=
cls
echo What is the product's selling price in th second station?
set /p sesell=
cls
echo How many times do you wish to repeat this loop?
set /p tirep=
cls 
echo OK. I've done the math and if the loop is repeated %tirep% you'll get:
echo.
set /a fi_sel_rep = "fisell * tirep"
set /a fi_cos_rep = "ficost * tirep"
set /a se_cos_rep = "secost * tirep"
set /a se_sel_rep = "sesell * tirep"
set /a tot_bal_fi= "fi_sel_rep - fi_cos_rep"
set /a tot_bal_sec = "intbal + tot_bal_fi"
set /a tot_bal-thi = "tot_bal_sec - sesell"
set /a tot_bal_fou = "tot_bal_thi + sesell"
echo %tot_bal_fou% credits in return.

所以,如果你能省下一些时间来纠正我可能非常明显的错误,那是我不知道的。

1 个答案:

答案 0 :(得分:0)

你的行

set /a tot_bal-thi = "tot_bal_sec - sesell"

(从结尾开始)

应该是

set /a tot_bal_thi = "tot_bal_sec - sesell"

(在tot_bal_thi中_而不是-

这会尝试创建一个新变量tot_bal-thi - 可能不是您所期望的。

BTW - 不需要每个set /a语句中的引号。另请注意,没有set选项的标准/a将分配字符串,但分配的字符串AND分配了字符串的变量名称将包含{{1}两侧的任何空格} operator。