2013-10-07 156 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