C# 租车计划#
我在学校的项目上需要帮助。我一直在研究它,最终找到了如何输出起始里程表和结束里程表=行驶总英里数的方法。对于总成本,我需要它加上每天15美元的租金,再加上每英里0.12美元。我该怎么做?以下是我现在掌握的代码:C# 租车计划#,c#,C#,我在学校的项目上需要帮助。我一直在研究它,最终找到了如何输出起始里程表和结束里程表=行驶总英里数的方法。对于总成本,我需要它加上每天15美元的租金,再加上每英里0.12美元。我该怎么做?以下是我现在掌握的代码: //Step 1: Declaring variables to store our information. decimal beginningOdometerDecimal; decimal endingOdometerDecimal; decimal rentedDecimal;
//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。我想我用的代码不对。有人能帮我吗?我被困住了,已经尝试了很多。谢谢 如果
rentedDecimal
是租车的天数,那么您的计算应该是:
finalCostDecimal = (totalMilesDecimal * 0.12m) + (rentedDecimal * 15.0m);
每天租用15美元,另加每英里0.12美元 (每天租用15美元)加上(每英里0.12美元) (租用15美元*天)+(行驶0.12美元*英里)
这是三年级的基本算术:(@Gunnar Bates)当你开始编程时,在写代码之前写下你必须做的事情可能更容易。(例如,写下所有需要的计算)我想你应该知道如何计算,但你被代码弄糊涂了。@JoelCoehoorn:至少他有一些代码要处理……这意味着他已经在这方面付出了很大的努力!继续你的工作。这些问题很少是算术问题,但如何用代码表达它。这就是为什么。+1 f或者问,而不是把头撞在墙上,然后放弃。可能应该加上括号,以便更容易阅读:)
finalCostDecimal = (15 * rentedDecimal) + (0.12 * totalMilesDecimal)