1

残高、毎月の支払い額、および金利を考慮して、特定の月数の後に残りのローン残高を計算するプログラムを 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

コードで何が間違っていますか? 私のアルゴリズムは正しいと思いました。

4

1 に答える 1

2

現時点では1を掛けているだけなので、利率は.12である必要があります。したがって、残高に1000を加算してから、支払いを減算します。

于 2012-10-24T04:15:11.193 に答える