Bifalgorithm post · Computer science one · Paying the Piper
How does the PHP loan amortization program process monthly payments?
How does the PHP loan amortization program process monthly payments? (Computer science one · Paying the Piper) — "The full solution can be found in Code Sample…
Ideas in this flowchart
- Code Sample 39.8 calculates and displays an amortized loan payment schedule.
- The program checks whether exactly three command-line arguments were provided.
- If the argument count is invalid, the program prints usage information and exits.
- With valid arguments, the program converts the principal, APR, and number of months to numeric values.
- The monthly interest rate is calculated by dividing the APR by twelve.
- The monthly payment is calculated using the loan-payment formula.
- The monthly payment is rounded to the nearest cent.
- The program prints the principal, APR, number of months, and calculated monthly payment.
- For the first n−1 payments, a loop processes each monthly installment.
- Each iteration calculates the monthly interest from the current balance and rounds it.
- The monthly principal payment is found by subtracting interest from the monthly payment.
- The balance is reduced by the monthly principal payment.
- Each iteration prints the payment number, interest, principal payment, and new balance.
- The final month is handled separately.
- The final interest is calculated from the remaining balance and rounded.
- The last payment equals the remaining balance plus the final interest.
- The program prints the amount of the last payment.