float loan_amount=5000;
float interestRate=12;
int months=12;
cal_loan(5000,12,12);
}
void cal_loan(float loan_amount,float interestRate,int months){
float balance;
int n=1;
int term=1;
float monthlyPayment;
float effectiveInterest;
float interest;
float principal;
float total_interest=0;
//Calculate your effective interest J.
effectiveInterest=interestRate/(100*12);
//Calculate (1+J)-N
monthlyPayment=loan_amount*(effectiveInterest/(1-pow(1+effectiveInterest,-months)));
//Display
balance=loan_amount;
println("Loan Amount $ = "+loan_amount);
println("Loan Term = "+months+" month(s)");
println("Interest Rate = "+interestRate+"%");
println("Payment per months = "+monthlyPayment);
println("Payment No. | Interset | Principal | Unpaid Balance | Total Interest to Date");
while(term<=months){
interest = effectiveInterest*balance;
principal=monthlyPayment-interest;
balance=balance-principal;
total_interest=total_interest+interest;
println(" "+term+" $"+interest+" $"+principal+" $"+balance+" $"+total_interest);
term=term+1;
}
}
No comments:
Post a Comment