Write a program to create an output file containing a customized loan amortization table. Your program will prompt the user to enter the amount borrowed (the principal), the annual interest rate, and the number of payments (n). The payment must be rounded to the nearest cent. After the payment has been rounded to the nearest cent, the program will write to the output file n lines showing how the debt is paid off.
Code:
#include <stdio.h>
#include <math.h>
int main (void)
{
int num_payments; // length of the loan
int Principle; // amount of the loan
float InterestRate;
float i, n, p;
float PaymentAmount;
printf("Please enter loan amount: ");
scanf("%d", &Principle);
printf("\nPlease enter annual interest rate: ");
scanf("%f", &InterestRate);
printf("\nPlease enter the number of payments: ");
scanf("%d", &num_payments);
i = InterestRate/12;
n = num_payments;
p = Principle;
while (num_payments>0)
{
PaymentAmount = (i*p)/(1-pow((1+i),-n));
p = p - PaymentAmount + ((i/100)*p);
n = n-1;
printf ("\nNumber of Payments: %d Amount per payment: %f\n", num_payments, PaymentAmount);
num_payments = num_payments - 1;
}
getchar ();
return 0;
}
So far this is what I've came up with but I don't know if it's correct. Any help would be appreciated.