I got my loan calculator to work perfect thanks to some help. I have the output
ID: 3549633 • Letter: I
Question
I got my loan calculator to work perfect thanks to some help. I have the output formatted in 4 colums but I cant think of a way to print the first 3 rows with a " " then print the the last 3 rows. The following table is right but i only need 6 rows
Month Interest Principal Balance
1 $19600.00 $107548.36 $2692451.75
2 $18847.16 $108301.20 $2584150.50
3 $18089.05 $109059.30 $2475091.25
4 $17325.64 $109822.72 $2365268.50
5 $16556.88 $110591.48 $2254677.00
6 $15782.74 $111365.62 $2143311.50
7 $15003.18 $112145.18 $2031166.38
8 $14218.16 $112930.20 $1918236.12
9 $13427.65 $113720.70 $1804515.38
10 $12631.61 $114516.75 $1689998.62
11 $11829.99 $115318.37 $1574680.25
12 $11022.76 $116125.59 $1458554.62
13 $10209.88 $116938.48 $1341616.12
14 $9391.31 $117757.05 $1223859.12
15 $8567.01 $118581.34 $1105277.75
16 $7736.94 $119411.41 $985866.31
17 $6901.06 $120247.30 $865619.00
18 $6059.33 $121089.02 $744530.00
19 $5211.71 $121936.65 $622593.38
20 $4358.15 $122790.20 $499803.16
21 $3498.62 $123649.73 $376153.41
22 $2633.07 $124515.29 $251638.12
23 $1761.47 $125386.89 $126251.23
24 $883.76 $126264.60 $0.00
int Month;
monPayment = (Principal * (Interest/100)/12) * (pow(1+(Interest/100)/12, Months) / (pow(1+(Interest/100)/12, Months) -1));
for(Month = 1; Month <= Months; Month++)
{
AccInterest = (Principal) * (Interest/100)/12;
appPrincipal = monPayment - AccInterest;
endBalance = Principal - monPayment + AccInterest;
if(Month == Months) endBalance = 0;
cout << Month << endl;
cout << "Starting Principal: $" << Principal << endl;
cout << "Payment is: $" << monPayment << endl;
cout << "Accured interest is: $" << AccInterest << endl;
cout << "Applied to Principal is: $" << appPrincipal << endl;
cout << "End balance: $" << endBalance << endl<<endl;
Principal = endBalance;
}
Explanation / Answer
inside the for loop,
Month ranges from 1 to Months
We want to print information for Month=1,2,3 and Month = Months-2,Months-1,Months
So, enclose the code which prints the numbers with a if condition:
if(Month<=3 || Month>=(Months-2)){
//code to print the numbers
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.