Hello,
I am a first year Comp Sci student and i am trying to finish this program. I am almost done with it but i just can't figure out one thing which is that, how do i show the initial principal amount under Principal heading in loop? the initial amount is $1000. I just need some help in order to finish my assignment (which i am already 99% done?) Thanks in advance and please scroll down for the code and its output, thanks again.
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
// Variables declraced
double principal, interest, monthlyAmount, monthlyInterest, principalPaid, interestPaid, total = 0;
int month = 0;
// User input screen menu
cout << "Enter the amount of the loan: ";
cin >> principal;
cout << "Enter the yearly interest rate: ";
cin >> interest;
cout << "Enter the monthly amount paid: ";
cin >> monthlyAmount;
cout << "\n";
// Headings for the loan calculation
cout << "Month";
cout << setw(6) << " " << "Principal";
cout << setw(5) << " " << "Interest Paid";
cout << setw(5) << " " << "Principal Paid";
cout << setw(5) << " " << "Remaining Balance\n";
cout << "\n";
while (principal > 0)
{
// Calculations for the loan
month++;
monthlyInterest = (interest/100) /12;
interestPaid = principal * monthlyInterest;
principalPaid = monthlyAmount - interestPaid;
principal = principal - principalPaid;
total += interestPaid;
// Settings for, to show the decimal precision
cout << fixed << showpoint << setprecision(2);
// Calculations output
cout << setw(2) << month;
cout << setw(16) << principal;
cout << setw(17) << interestPaid;
cout << setw(18) << principalPaid;
cout << setw(19) << principal << endl;
}
// Shows the result of the calculated loan
cout << "\n";
cout << "Number of months to pay off the loan: " << month << endl;
cout << endl;
cout << "Total interest paid on loan: $" << total << endl;
cout << endl;
cout << "You have a credit of: $" << principal << endl;
cout << endl;
cout << "\n";
return 0;
}
see under Principal it shows 965.00 but i want to show 1000 like start it from 1000...thats the only problem i m having wit it....
Enter the amount of the loan: 1000
Enter the yearly interest rate: 18
Enter the monthly amount paid: 50
Month [B]Principal[/B] 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
Number of months to pay off the loan: 24
Total interest paid on loan: $197.83
You have a credit of: $-2.17
Press any key to continue . . .