write a program that will compute a monthly payment You are
write a program that will compute a monthly payment.
You are to have, at least, 1 function ( other than main() ) in your program.
//am done with part one just need help with part 2
part one answer
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double payment , p, mir, y; //p = principle, mir = monthly interest rate, y = number of years.
double yir;
cout<<\"Enter the principle;\"<<endl;
cin>>p;
cout<<\"Enter the yearly interest rate:\"<<endl;
cin>>yir;
cout<<\"Enter the number of years:\"<<endl;
cin>>y;
y = 30;
yir = 9.5;
mir = (yir)/1200;
payment = 0;
double a=0, b=0, c=0, d=0, e=0, f=0;
a = 1+mir;
b = 1/a;
c = 12*y;
d = pow(b,c);
e = 1-d;
f = p * mir;
payment = f/e;
cout<<setprecision(2)<<fixed;
cout<<\"principle\"<<\" \"<<p<<\" \"<<\"Interest\"<<\" \"<<yir<<\" \"<<\"years\" <<\" \"<<y<<\" \"<<\"payment\"<<\" \"<<payment<<endl;
}
}
yir mir = ---- 1200 | .007916 |
a = 1 + mir | 1.007916 |
1 b = --- a | .992145514 |
c = 12 * y | 360 |
c d = b | .058497109 |
e = 1 - d | .94150289 |
f = p * mir | 554.12 |
f payment = --- e | 588.60 |
Solution
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void part2(int, double,double,double);
int main()
{
double payment ,p, mir, y; //p = principle, mir = monthly interest rate, y = number of years.
double yir;
cout<<\"Enter the principle: \"<<endl;
cin>>p;
cout<<\"Enter the yearly interest rate: \"<<endl;
cin>>yir;
cout<<\"Enter the number of years: \"<<endl;
cin>>y;
mir = (yir)/1200;
payment = 0;
double a=0, b=0, c=0, d=0, e=0, f=0;
a = 1+mir;
b = 1/a;
c = 12*y;
d = pow(b,c);
e = 1-d;
f = p * mir;
payment = f/e;
cout<<setprecision(2)<<fixed;
cout<<\"-------------------------------------------------------------------\"<<endl;
cout<<\"principle\"<<\" \"<<p<<\" \"<<\"Interest\"<<\" \"<<yir<<\" \"<<\"years\" <<\" \"<<y<<\" \"<<\"payment\"<<\" \"<<payment<<endl;
cout<<endl;
part2(y, payment,p,yir);
}
void part2(int y,double payment,double p,double yir)
{
cout<<\"Month\"<<\" \"<<\"Pay_Paid\"<<\" \"<<\"Total_Interest\"<<\" \"<<\"Monthy_Paid\"<<\" \"<<\"Principle_Paid\" <<\" \"<<\"Total_Principle\"<<\" \"<<\"Remaining_Balance\"<<endl;
int i;
double Total_Interest=0.0;
double Monthy_Paid;
double Principle_Paid;
double Total_Principle=0.0;
//cout<<\"hello payment is\"<<payment;
for(i=1;i<=y*12;i++)
{
Total_Interest=Total_Interest+payment;
Monthy_Paid=p*(yir)/1200;
Principle_Paid=payment-Monthy_Paid;
Total_Principle=Total_Principle+Principle_Paid;
p=p-Principle_Paid;
//cout<<\"Total_Principle is\"<<Total_Principle;
//cout<<\"p is\"<<p<<endl;
if( (i <=8) || (i>=y*12-8) )
{
if(i==353)
cout<<\"- - - - - - - - \"<<endl;
cout<<i<<\" \"<<payment<<\" \"<<Total_Interest<<\" \"<<Monthy_Paid<<\" \"<<Principle_Paid <<\" \"<<Total_Principle<<\" \"<<p<<endl;
}
}
}
-------------------------
output sample 1:-
Enter the principle:
70000
Enter the yearly interest rate:
9.5
Enter the number of years:
30
-------------------------------------------------------------------
principle 70000.00 Interest 9.50 years 30.00 payment 588.60
Month Pay_Paid Total_Interest Monthy_Paid Principle_Paid Total_Principle Remaining_Balance
1 588.60 588.60 554.17 34.43 34.43 69965.57
2 588.60 1177.20 553.89 34.70 69.14 69930.86
3 588.60 1765.79 553.62 34.98 104.11 69895.89
4 588.60 2354.39 553.34 35.26 139.37 69860.63
5 588.60 2942.99 553.06 35.53 174.90 69825.10
6 588.60 3531.59 552.78 35.82 210.72 69789.28
7 588.60 4120.19 552.50 36.10 246.82 69753.18
8 588.60 4708.78 552.21 36.39 283.20 69716.80
352 588.60 207186.48 40.32 548.27 65454.63 4545.37
- - - - - - - -
353 588.60 207775.07 35.98 552.61 66007.25 3992.75
354 588.60 208363.67 31.61 556.99 66564.24 3435.76
355 588.60 208952.27 27.20 561.40 67125.64 2874.36
356 588.60 209540.87 22.76 565.84 67691.48 2308.52
357 588.60 210129.47 18.28 570.32 68261.80 1738.20
358 588.60 210718.06 13.76 574.84 68836.64 1163.36
359 588.60 211306.66 9.21 579.39 69416.03 583.97
360 588.60 211895.26 4.62 583.97 70000.00 -0.00
----------------
output sample 2:-
Enter the principle:
50000
Enter the yearly interest rate:
10
Enter the number of years:
15
-------------------------------------------------------------------
principle 50000.00 Interest 10.00 years 15.00 payment 537.30
Month Pay_Paid Total_Interest Monthy_Paid Principle_Paid Total_Principle Remaining_Balance
1 537.30 537.30 416.67 120.64 120.64 49879.36
2 537.30 1074.61 415.66 121.64 242.28 49757.72
3 537.30 1611.91 414.65 122.65 364.93 49635.07
4 537.30 2149.21 413.63 123.68 488.61 49511.39
5 537.30 2686.51 412.59 124.71 613.32 49386.68
6 537.30 3223.82 411.56 125.75 739.06 49260.94
7 537.30 3761.12 410.51 126.79 865.86 49134.14
8 537.30 4298.42 409.45 127.85 993.71 49006.29
172 537.30 92416.04 38.67 498.63 45858.39 4141.61
173 537.30 92953.34 34.51 502.79 46361.18 3638.82
174 537.30 93490.65 30.32 506.98 46868.16 3131.84
175 537.30 94027.95 26.10 511.20 47379.37 2620.63
176 537.30 94565.25 21.84 515.46 47894.83 2105.17
177 537.30 95102.55 17.54 519.76 48414.59 1585.41
178 537.30 95639.86 13.21 524.09 48938.68 1061.32
179 537.30 96177.16 8.84 528.46 49467.14 532.86
180 537.30 96714.46 4.44 532.86 50000.00 -0.00
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.



