Question: Write a C program to read loan data ( principal , interest rate, period ) , and compute monthly payment, total payment, monthly balance. First

Write a C program to read loan data (principal, interest rate, period), and compute monthly payment, total payment,
monthly balance. First type and run the program to make sure everything works. Then replace two boxes with two functions:
Line 27, with one value-returning function.
Lines 48-50, with void function to compute items needed.
No global variable can be used!
4 #include
5
6 int main()
7{
8 float principal; // loan principal
9 float annualintrate; // annual interest rate
10 float monintrate; // monthly interest rate
11 int numofyears; // loan period in years
12 int numofmonths; // loan period in months
13 float monpmt; // monthly payment
14 float totalpmt; // total patment paid over the loan years
15 float tointerest; // interest amount of monthly payments
16 float toprincipal; // amount of monthly payment deducted from loan balance
17 float balance; //monthly balance
18
19// prompt and read loan components
20 printf("
enter principal,, annual inteerest rate and load period, in years: ");
21 scanf_s("%f %f %d", &principal, &annualintrate, &numofyears);
22
23// calculating monthly and total payment
24 monintrate = annualintrate /1200;
25 numofmonths = numofyears *12;
26
27 monpmt =(principal * monintrate); /(1.0-1.0/ pow(1+ monintrate, numofmonths))
28 totalpmt = monpmt * numofmonths;
29
30// printing results
31 printf("
");
32 printf("Principal -%.2f
", principal);
33 printf("Annual interest rate =%.2f
", annualintrate);
34 printf("Years of loan =%d
", numofyears);
35 printf("Monthly Payment =%.2f
", monpmt);
36 printf("Total payment =%.2f
", totalpmt);
37 printf("
");
38
39// calculate loan balance for 24 months
40// the header must be printed before the loop
41 printf("Month to interest to principal Balance
");
42 printf("--------------------------------------
");
43
44 balance = principal; // original balance: entire loan
45
46 for (intmonnum =1; monnum <=24; monnum++)//the forr-loop and printing must stau in their own current place. do not move them to insdide function.
47{
48 tointerest = balance * monintrate; // amount of loan used for interest
49 toprincipal = monpmt - tointerest; // amount of loan that reduces balance
50 balance -= toprincipal; // adjust balance
51 printf("%4d %8.2f %8.2f %8.2f
", monnum, tointerest, toprincipal, balance);
52}
53}
output
enter principal, annual interest rate and load period, in years: 4000007.7530
principal =400000.00
annual interest rate =7.75
years of loan =30
monthly payment =2865.65
total payment =1031635.63
month to interest to principal balance
----------------------------------------------
12583.33282.32399717.69
22581.51284.14399433.53
32579.67285.98399147.56
42577.83287.83398859.75
52575.97289.69398570.06
62574.10291.56398278.50
72572.22293.44397985.06
82570.32295.33397689.72
92568.41297.24397392.47
102566.49299.16397093.31
112564.56301.09396792.22
122562.62303.04396489.19
132560.66305.00396184.19
142558.69306.97395877.22
152556.71308.95395257.34
162554.71310.94395257.34
172552.70312.95394944.41
182550.68314.97394312.44
192548.65317.95394312.44
202546.60

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!