simulating a payment structure
Hello I am currently stuck on this code, it doesn't display the list and when I do change one code it endlessly loop.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double balance, monthly, apr, apr_monthly, start_bal, interest, end_bal;
int months = 0;
cout << fixed << setprecision(2);
cout << "What is the outstanding balance? ";
cin >> balance;
cout << "What is the APR? ";
cin >> apr;
do
{
start_bal = balance;
cout << "How much do you pay every month? ";
cin >> monthly;
cout <<"\n\nThe table shows how long it will take to pay:\n\n";
if( monthly < 0)
{
cout << "How much do you pay every month? ";
cin >> monthly;
}
while( start_bal > 0)
{
apr_monthly = (apr/12)/100;
interest = start_bal*apr_monthly;
end_bal = start_bal + interest - monthly;
months++;
if(start_bal > monthly)
{
cout << setw(5) << months << setw(10) << start_bal << interest
<< setw(10) << apr_monthly << setw(5) << end_bal;
start_bal = end_bal;
}
}
}while(balance > 0);
return 0;
}
|
This is what the output should be
What is the outstanding balance? 2000
What is the APR? 24
How much do you pay every month? -10
How much do you pay every month? -100
How much do you pay every month? 125
The table shows how long it will take to pay:
Month Start Interest Monthly End
1 2000.00 40.00 125.00 1915.00
2 1915.00 38.30 125.00 1828.30
3 1828.30 36.57 125.00 1739.87
4 1739.87 34.80 125.00 1649.66
5 1649.66 32.99 125.00 1557.66
6 1557.66 31.15 125.00 1463.81
7 1463.81 29.28 125.00 1368.09
8 1368.09 27.36 125.00 1270.45
9 1270.45 25.41 125.00 1170.86
10 1170.86 23.42 125.00 1069.27
11 1069.27 21.39 125.00 965.66
12 965.66 19.31 125.00 859.97
13 859.97 17.20 125.00 752.17
14 752.17 15.04 125.00 642.22
15 642.22 12.84 125.00 530.06
16 530.06 10.60 125.00 415.66
17 415.66 8.31 125.00 298.97
18 298.97 5.98 125.00 179.95
19 179.95 3.60 125.00 58.55
20 58.55 1.17 125.00 -65.28 |
The entire code cannot have a break in any statement.
Last edited on
This might be a start to getting back on track:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double balance = 0, monthly = 0, apr = 0, interest = 0;
int months = 0;
cout << fixed << setprecision(2);
cout << "What is the outstanding balance? ";
cin >> balance;
cout << "What is the APR? ";
cin >> apr;
cout << "How much do you pay every month? ";
cin >> monthly;
cout <<"\nThe table shows how long it will take to pay:\n\n";
while( balance > 0)
{
cout
<< setw(5) << months << setw(10) << balance << setw(10) << interest << endl;
interest = balance * apr/1200;
balance = balance + interest - monthly;
months++;
}
return 0;
}
|
0 2000.00 0.00
1 1915.00 40.00
2 1828.30 38.30
3 1739.87 36.57
4 1649.66 34.80
5 1557.66 32.99
6 1463.81 31.15
7 1368.09 29.28
8 1270.45 27.36
9 1170.86 25.41
10 1069.27 23.42
11 965.66 21.39
12 859.97 19.31
13 752.17 17.20
14 642.22 15.04
15 530.06 12.84
16 415.66 10.60
17 298.97 8.31
18 179.95 5.98
19 58.55 3.60
Program ended with exit code: 0 |
Last edited on
Topic archived. No new replies allowed.