2

我的学校项目需要帮助。我一直在研究它,终于想出了如何输出开始里程表和结束里程表 = 总行驶里程。对于总成本,我需要它增加每天租用的 15 美元,再加上每英里 0.12 美元。我该怎么做?这是我现在拥有的代码:

//Step 1: Declaring variables to store our information.
decimal beginningOdometerDecimal;
decimal endingOdometerDecimal;
decimal rentedDecimal;
decimal totalSaleDecimal;
decimal averageSalesDecimal;
decimal carsReturned;
decimal totalMilesDecimal;
decimal finalCostDecimal;

//Step 2: Get the information from the user.
beginningOdometerDecimal = Decimal.Parse(txtBegin.Text);
endingOdometerDecimal = Decimal.Parse(txtEnd.Text);
rentedDecimal = Decimal.Parse(txtRent.Text);

//Step 3: Mathmatematical Calculations.
totalMilesDecimal = endingOdometerDecimal - beginningOdometerDecimal;
finalCostDecimal = totalMilesDecimal * (Decimal)0.12 + rentedDecimal + 15;

如您所见,我使用的 finalCostDecimal 等于 totalmilesdecimal * $0.12 + rentedDecimal + 15。我认为我使用的代码不正确。任何人都可以在这里帮助我吗?我被卡住了,已经尝试了很多。谢谢!

4

2 回答 2

5

如果rentedDecimal是租车的天数,那么你的计算应该是:

 finalCostDecimal = (totalMilesDecimal * 0.12m) + (rentedDecimal * 15.0m);
于 2013-10-07T23:51:02.777 回答
4

每天租金 15 美元,外加每英里 0.12 美元

(每天租金 15 美元)加上(每英里 0.12 美元)

(15 美元 * 租用天数)+(0.12 美元 * 行驶里程)

finalCostDecimal = (15 * rentedDecimal) + (0.12 * totalMilesDecimal)
于 2013-10-07T23:52:13.207 回答