hey need some help with my loan program
i have two problems
how do you add the total of the variable sumtin from a while loop
and
i need to show the inital loan first then after the calculations are done show it again
like i want it to show 1000 then 945 then 945 then 930 that sorta thing
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double loan,yrint,mptpd,sumtin;
double decint,prince,totalprnce;
int month = 0;
cout << "Enter the amount of loan: ";
cin >> loan;
cout << "Enter the yearly interest: ";
cin >> yrint;
cout << "Enter the monthly amount paid: ";
cin >> mptpd;
cout << endl;
cout << "Month";
cout << setw(20) << "Princpal Interest";
cout << setw(10) << "Paid";
cout << setw(20) << "Principal Paid";
cout << setw(20) << "Remaining Balance" << endl;
while (loan > 0)
{
month++;
decint = yrint/100/12;
sumtin = loan*decint;
prince = mptpd - sumtin;
loan = loan - prince;
cout << fixed << showpoint << setprecision(2);
cout << setw(4) <<month;
cout << setw(17) << loan;
cout << setw(15) << sumtin;
cout << setw(15) << prince;
cout << setw(20) << loan;
cout << endl;
}
cout << "The total months you need to pay off is " << month << endl;
cout << "Total interest paid on loan " << sumtin << endl;
cout << "You have a credit of " << loan << endl;
return 0;
}
HERES THE OUTPUT I NEED THE PRINCIPLE INTEREST TO SHOW 1000 first
Enter the amount of loan: 1000
Enter the yearly interest: 18
Enter the monthly amount paid: 50
Month Princpal Interest Paid Principal Paid Remaining Balance
1 965.00 15.00 35.00 965.00
2 929.48 14.48 35.52 929.48
3 893.42 13.94 36.06 893.42
4 856.82 13.40 36.60 856.82
5 819.67 12.85 37.15 819.67
6 781.97 12.30 37.70 781.97
7 743.70 11.73 38.27 743.70
8 704.85 11.16 38.84 704.85
9 665.42 10.57 39.43 665.42
10 625.40 9.98 40.02 625.40
11 584.79 9.38 40.62 584.79
12 543.56 8.77 41.23 543.56
13 501.71 8.15 41.85 501.71
14 459.24 7.53 42.47 459.24
15 416.13 6.89 43.11 416.13
16 372.37 6.24 43.76 372.37
17 327.95 5.59 44.41 327.95
18 282.87 4.92 45.08 282.87
19 237.11 4.24 45.76 237.11
20 190.67 3.56 46.44 190.67
21 143.53 2.86 47.14 143.53
22 95.68 2.15 47.85 95.68
23 47.12 1.44 48.56 47.12
24 -2.17 0.71 49.29 -2.17
The total months you need to pay off is 24
Total interest paid on loan 197.83
You have a credit of -2.17
Press any key to continue . . .