Question: Write a c program to help a prospective borrower calculate the monthly payment for a loan. The program also prints the amortization(payoff)table to show the
Write a c program to help a prospective borrower calculate the monthly payment for a loan. The program also prints the amortization(payoff)table to show the balance of the loan after monthly payment. prompt user for input; 1)Amount of the loan: 2)Interet rate per year: 3)number of years: formula; NM=(NY *12) IM =(IY/12) P=(1+IM)NM Q =(P/(P-1)) MP=(PR*IM*Q) where NY= Scheduled number of years to amortize the loan NM=Scheduled number of months for the loan IY=Interest rate per year(as a percentage) IM=Interest rate/month (decimal) PR=Principal (the amount of the loan) P= The value of (1+IM)NM Q= The value of P/(P-1) MP= Monthly payment
I have got this program working but I need it to be in 3 functions and they should be called calculateMonthlyPayment, printInormation, and printAmortizationTable. I would also like to put in do while loops to check after the scanf statement to see if they put in 0 or a negative number. Also if you could use pointers in the void functions that would be great.
Code I have now.
#include
int main() { double principal; /* Principal */ double intYear; /* interest rate/year */ double intMonth; /* interest rate/month */ double monthPay; /* Monthly payment */ double oldBalance; /* Old balance */ double intPaid; /* Interest paid */ double princPaid; /* Principal paid */ double newBalance; /* New balance */ double P; /* Value of pow ((1+intMonth),numMonth) */ double Q; /* The value of P/(P-1) */ int numYear; /* Number of year */ int numMonth; /* Number of month */ int month;
/* user input */ printf("Amount of the loan (Principal)? "); scanf("%lf",&principal); printf("Interest rate per year (percent)? "); scanf("%lf",&intYear); printf("Number of years? "); scanf("%d",&numYear); numMonth = (numYear * 12); intMonth = (intYear / 12) / 100; P = pow((1 + intMonth),numMonth); Q = P/(P-1);monthPay = (principal * intMonth * Q);
printf(" The amount of the loan (principal):\t%10.2lf ",principal); printf("Interest rate/year (percent):\t\t%10.2lf ",intYear); printf("Interest rate/month (decimal):\t\t%14f ",intMonth); printf("Number of years:\t\t\t%7d ",numYear); printf("Number of months:\t\t\t%7d ",numMonth); printf("Monthly payment:\t\t\t%10.2lf ",monthPay);
oldBalance=principal; printf("Month Old Monthly Interest Principal New "); printf(" Balance Payment Paid Paid Balance ");
for (month = 1; month<= numMonth; month++) { intPaid = oldBalance * intMonth; princPaid = monthPay - intPaid; newBalance = oldBalance - princPaid; printf("%d\t%10.2lf\t%8.2lf\t%6.2lf\t%8.2lf\t%10.2lf ",month ,oldBalance ,monthPay ,intPaid ,princPaid ,newBalance); oldBalance = newBalance; } printf(" Total amount paid: %.2lf ",numMonth*monthPay); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
