计算剩余贷款余额

时间:2012-10-24 04:09:53

标签: c

考虑到余额,每月付款金额和利率,我试图在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

我的代码中出错了什么?我认为我的算法是正确的。

1 个答案:

答案 0 :(得分:2)

您的利率需要为.12,因为此时您只需乘以1,因此在余额中加1000,然后减去付款。