所以我需要創建一個方法,我輸入歲,量和控制檯程序會輸出一個圖表,顯示了雙倍餘額折舊。雙倍餘額遞減在C#
這就是我所擁有的。
static void doubleDecliningBalance(double amount, int years)
{
Console.WriteLine("{0,-20}{1,10}", "Year", "Depreciation");
Console.WriteLine("----------------------------------");
int count = 0;
double depreciation, amountLeft = 0;
while (count < years)
{
amountLeft = amount;
count = count + 1;
depreciation = (amountLeft * (2/years));
amountLeft = amount - depreciation;
Console.WriteLine("{0,-20}{1,10:C2}", count, amountLeft);
}
}
現在,當我運行該程序,它不會貶值。這個公式是正確的我認爲我很困惑爲什麼它不會貶值,這意味着如果我輸入5年和5000美元的金額;它將在所有5年中顯示5000。
你永遠不會更新'amount',所以你的輸出將是每個循環相同。 –
這將是學習使用調試器來逐步執行代碼的完美時間,這會在循環中顯示出兩到三個問題。 –