2013-10-07 84 views
2

我需要帮助与我的学校项目。我一直在研究它,并最终想出如何输出开始的里程表和结束里程表=总里程驱动。对于总成本,我需要每天增加15美元租金,再加上每英里0.12美元。我将如何做到这一点?下面是代码我现在有:汽车租赁计划C#

//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.我不认为我用正确的代码。任何人都可以在这里帮我吗?我卡住了,并尝试了很多。谢谢!

+5

这是基本的三年级算术:( –

+2

@Gunnar Bates当你开始编程时,编写代码之前可能更容易写下你要做的事情。 (例如写下所有需要的计算)我假设你应该知道如何进行计算,但是你被代码弄糊涂了。 –

+0

@JoelCoehoorn:至少他有一些代码可以和.. – NotMe

回答

5

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

finalCostDecimal = (totalMilesDecimal * 0.12m) + (rentedDecimal * 15.0m); 
+0

可能应该放在括号内,以便阅读:) –

+0

感谢您回答如此之快。它现在有效:D – Gunnar

4

$ 15租用外加每英里

(15天租$)加($ 0.12 $ 0.12每英里)租用

($ 15 *天)+($ 0.12 *英里驱动)

finalCostDecimal = (15 * rentedDecimal) + (0.12 * totalMilesDecimal) 
+0

非常感谢!它计算正确。 – Gunnar