Code:
#include <stdio.h>
#include <math.h>
double CollectInput (double a, double i, int n, int Numberofmonths, int PaymentNumber, int count);
double Calculate (int n,double a, double i,double PaymentAmount,double PaymentNumber,
double Numberofmonths, int count, double AmountInterest,
double AmountPrinciple, double LoanBlance);
double Amortization (double a, double InterestRate, double LoanAmount, int PaymentNumber,
double AmountPrinciple, double AmountInterest, double LoanBlance, double PaymentAmount);
main ()
{
char data;
int TermLoan, // length of the loan
PaymentNumber, //number of payments made
Numberofmonths, //Number of months in the loan
count,
n,c; //Letters used for the calculations
double AmountPrinciple, //Amount paid on principle
AmountInterest, //amount paid to interest
LoanBlance, //amount owed on loan\ count,
CurrentBlance,
LoanAmount, //amount of the loan
InterestRate, //interest rate on loan
a,i,
PaymentAmount; //amount paid to loan
printf ("This startes you loan program");
double returnedValue = CollectInput (a, i, n, Numberofmonths, PaymentNumber, count);
double returedValue1 = Calculate (n, a, i, PaymentAmount, PaymentNumber, Numberofmonths, count,
AmountInterest, AmountPrinciple, LoanBlance);
printf ("Do you have data to add?");
scanf ("%c", &data);
while (data == 'y' || data == 'Y');
{
CollectInput (a, i, n, Numberofmonths, PaymentNumber, count);
Calculate (n, a, i, PaymentAmount, PaymentNumber, Numberofmonths, count,
AmountInterest, AmountPrinciple, LoanBlance);
Amortization (a, InterestRate, LoanAmount, PaymentNumber,
AmountPrinciple, AmountInterest, LoanBlance, PaymentAmount);
}
printf ("hit enter to end");
getchar ();
getchar ();
return 0;
}
//****************************************************************
//Start of the function to collect data
//****************************************************************
double CollectInput (double a, double i, int n, int Numberofmonths, int PaymentNumber, int count)
{
int TermLoan,
c ;
double LoanAmount,
InterestRate,
CurrentBlance;
while (scanf("%lf%d%lf", &LoanAmount, &TermLoan, &InterestRate) != 3
|| (LoanAmount < 0 || TermLoan < 0 || InterestRate < 0 ))
{
while ((c = getchar()) != '\n' && c != EOF);
printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n");
}
CurrentBlance = LoanAmount;
Numberofmonths = TermLoan;
i = InterestRate/ 100;
n = Numberofmonths;
a = CurrentBlance;
PaymentNumber = 0;
count = 0;
return i, n, a, PaymentNumber, count;
} //end of collect data
//********************************************************************
//Start of Calculate function
//*************************************************************
double Calculate (int n,double a, double i,double PaymentAmount,double PaymentNumber,
double Numberofmonths, int count, double AmountInterest,
double AmountPrinciple, double LoanBlance)
{
PaymentAmount = ((i/12*a)/(1-pow((1+(i/12)),-n)));
while(PaymentNumber < Numberofmonths)
{
PaymentNumber++; //Start number of months for amortization schedule
count++;
AmountInterest = a * (i/12);
AmountPrinciple = PaymentAmount - AmountInterest;
LoanBlance = a - AmountPrinciple;
a = LoanBlance;
return a, PaymentNumber, LoanBlance, PaymentAmount,
AmountPrinciple, AmountInterest;
}//end of while loop
} //end of Calculate Function
//*********************************************************************
//State of print function
//************************************************************
double Amortization (double a, double InterestRate, double LoanAmount, int PaymentNumber,
double AmountPrinciple, double AmountInterest, double LoanBlance, double PaymentAmount)
{
printf ("\amortization Schedule\n");
printf ("_____________________\n");
printf ("CurrentBlance %.2f\n", a);
printf ("InterestRate %.2f\n", InterestRate);
printf ("PaymentNumber %d\n", PaymentNumber);
printf ("LoanBlance %.2f\n", LoanBlance);
printf ("PaymentAmount %.2f\n", PaymentAmount);
printf ("AmountPrinciple %.2f\n", AmountPrinciple);
printf ("AmountInterest %.2f\n", AmountInterest);
printf ("_______________________\n\n");
return 0;
} //end of Amortization print function