I did that and it prints ok. THe only issue that I have knwo is that once i run the program it only prints to payment 8 and the I get a lot of wried letters. i cdan run 6 or 7 months for the payment and the program runs fine. Is there a buffer that is not allowing it to print out more then that many
this is what i get
Code:
start of program
Please enter in loan amount, Term of Loan in months and Interest Rate.
1000.00 8 8
amortization Schedule
CurrentBlance 877.89
PaymentNumber 1
LoanBlance 877.89
PaymentAmount 128.78
AmountPrinciple 122.11
AmountInterest 6.67
_______________________
amortization Schedule
CurrentBlance 754.96
PaymentNumber 2
LoanBlance 754.96
PaymentAmount 128.78
AmountPrinciple 122.93
AmountInterest 5.85
_______________________
amortization Schedule
CurrentBlance 631.22
PaymentNumber 3
LoanBlance 631.22
PaymentAmount 128.78
AmountPrinciple 123.75
AmountInterest 5.03
_______________________
amortization Schedule
CurrentBlance 506.64
PaymentNumber 4
LoanBlance 506.64
PaymentAmount 128.78
AmountPrinciple 124.57
AmountInterest 4.21
_______________________
amortization Schedule
CurrentBlance 381.24
PaymentNumber 5
LoanBlance 381.24
PaymentAmount 128.78
AmountPrinciple 125.40
AmountInterest 3.38
_______________________
amortization Schedule
CurrentBlance 255.01
PaymentNumber 6
LoanBlance 255.01
PaymentAmount 128.78
AmountPrinciple 126.24
AmountInterest 2.54
_______________________
amortization Schedule
CurrentBlance 127.93
PaymentNumber 7
LoanBlance 127.93
PaymentAmount 128.78
AmountPrinciple 127.08
AmountInterest 1.70
_______________________
amortization Schedule
CurrentBlance -1.#J
PaymentNumber 8
LoanBlance -1.#J
PaymentAmount 128.78
AmountPrinciple -1.#J
AmountInterest -1.#J
_______________________
hit enter to end
and here is my program
Code:
#include <stdio.h>
#include <math.h>
typedef struct loan {
int c,n, count, PaymentNumber;
int TermLoan;
int Numberofmonths;
double InterestRate,
LoanAmount,
a, i,
LoanBlance,
PaymentAmount,
AmountPrinciple,
AmountInterest,
CurrentBlance;
} loan;
void CollectInput( loan *details );
void Calculate ( loan *details );
int main()
{
loan details;
printf( "start of program\n" );
CollectInput( &details );
Calculate( &details );
printf( "hit enter to end" );
getchar();
getchar();
return 0;
}
//****************************************************************
//Start of the function to collect data
//****************************************************************
void CollectInput( loan *details )
{
printf ("Please enter in loan amount, Term of Loan in months and Interest Rate.\n");
while (scanf("%lf%d%lf", &details->LoanAmount, &details->TermLoan, &details->InterestRate) != 3
|| (details->LoanAmount < 0 || details->TermLoan < 0 || details->InterestRate < 0 ))
{
while ((details->c = getchar()) != '\n' && details->c != EOF);
printf ("Please re-enter in loan amount, Term of Loan in months and Interest Rate.\n");
}
return;
}
//********************************************************************
//Start of Calculate function
//*************************************************************
void Calculate( loan *details )
{
void Amortization ( loan *details );
int count;
details->CurrentBlance = details->LoanAmount;
details->Numberofmonths = details->TermLoan;
details->i = details->InterestRate/ 100;
details->n = details->Numberofmonths;
details->a = details->CurrentBlance;
details->PaymentNumber = 0;
count = 0;
details->PaymentAmount = ((details->i/12*details->a)/(1-pow((1+(details->i/12)),-details->n)));
while(details->PaymentNumber < details->Numberofmonths)
{
details->PaymentNumber++; //Start number of months for amortization schedule
count++;
details->AmountInterest = details->a * (details->i/12);
details->AmountPrinciple = details->PaymentAmount - details->AmountInterest;
details->LoanBlance = details->a - details->AmountPrinciple;
Amortization( details );
details->a = details->LoanBlance;
}
}
//*********************************************************************
//State of print function
//************************************************************
double Amortization( loan *details )
{
printf("amortization Schedule\n");
printf ("CurrentBlance %.2f\n", details->a);
printf ("PaymentNumber %d\n", details->PaymentNumber);
printf ("LoanBlance %.2f\n", details->LoanBlance);
printf ("PaymentAmount %.2f\n", details->PaymentAmount);
printf ("AmountPrinciple %.2f\n", details->AmountPrinciple);
printf ("AmountInterest %.2f\n", details->AmountInterest);
printf ("_______________________\n\n");
}