我试图用C语言编写一个程序,根据余额、月供金额和利率,计算给定月份数后的剩余贷款余额。(每月增加(余额*(利率/12)),减少支付金额。)
我计算每月余额的代码如下:

for (i = 1; i <= n; i++) {
    loanAmount += (loanAmount * (intRate/12));
    loanAmount -= monthlyPayment;
    printf("The balance after month %d is %.2f\n", i, loanAmount);
}

我输入了一些值(loanAmount = 1000intRate = 12monthlyPayment = 100n = 3,),我希望结果在第1个月后为910.00,第2个月后为819.10,第3个月后为727.29。但是,我得到了以下结果:
Enter the loan amount:
1000
Enter the interest rate:
12
Enter the monthly payment amount:
100
Enter the number of monthly payments:
3
The balance after month 1 is 1900.00
The balance after month 2 is 3700.00
The balance after month 1 is 7300.00

我的代码哪里做错了?我认为我的算法是正确的。

最佳答案

你的利率需要是。12,因为你现在只是乘以1,所以加上1000的余额,然后减去付款。

关于c - 计算贷款余额,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13042900/

10-11 23:19
查看更多