Need help with program

Write a program to compute the amount of money you will have on an initial amount invested for a number of years at an annual percentage rate of interest. The user also adds a fixed amout to the investment each month. Show a table of the running amount month (see below). Ask the user for the principal, the annual rate, the number of years and the amount he can afford to add to the investment each month. All dollar amount is to be rounded to two decimal places.

What is the principal? 500
What is the % annual rate? 12
How many years? 4
How much would you like to put away each month? 50
Month# Interest Monthly New
Amount Amount Amount
1 5.00 50.00 555.00
2 5.55 50.00 610.55
3 6.11 50.00 666.66
4 6.67 50.00 723.32
5 7.23 50.00 780.56
6 7.81 50.00 838.36
7 8.38 50.00 896.74
8 8.97 50.00 955.71
9 9.56 50.00 1015.27
10 10.15 50.00 1075.42
11 10.75 50.00 1136.18
12 11.36 50.00 1197.54
13 11.98 50.00 1259.51
14 12.60 50.00 1322.11
15 13.22 50.00 1385.33
16 13.85 50.00 1449.18
17 14.49 50.00 1513.67
18 15.14 50.00 1578.81
19 15.79 50.00 1644.60
20 16.45 50.00 1711.05
21 17.11 50.00 1778.16
22 17.78 50.00 1845.94
23 18.46 50.00 1914.40
24 19.14 50.00 1983.54
25 19.84 50.00 2053.38
26 20.53 50.00 2123.91
27 21.24 50.00 2195.15
28 21.95 50.00 2267.10
29 22.67 50.00 2339.77
30 23.40 50.00 2413.17
31 24.13 50.00 2487.30
32 24.87 50.00 2562.17
33 25.62 50.00 2637.80
34 26.38 50.00 2714.17
35 27.14 50.00 2791.32
36 27.91 50.00 2869.23
37 28.69 50.00 2947.92
38 29.48 50.00 3027.40
39 30.27 50.00 3107.67
40 31.08 50.00 3188.75
41 31.89 50.00 3270.64
42 32.71 50.00 3353.34
43 33.53 50.00 3436.88
44 34.37 50.00 3521.25
45 35.21 50.00 3606.46
46 36.06 50.00 3692.52
47 36.93 50.00 3779.45
48 37.79 50.00 3867.24

I have completed the program but I dont get the exact same results as above. Can anyone help me?

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double Principal,AnnRate,MonthlyRate,MonthlyIntAmt, NewPrin,HisAmt,intyears, months;
cout<<"What is the Principle?";
cin>>Principal;
cout<<"What is the AnnRate?";
cin>>AnnRate;
MonthlyRate=AnnRate/12/100;// ineterest rate of 10%
cout<<"How many years?";
cin>>intyears;
intyears=4;
cout<<"How much would you like to put away each month?";
cin>>MonthlyIntAmt;
MonthlyIntAmt=50;
NewPrin=Principal;
for(months=1;months<= 12 * intyears;months ++)
{
MonthlyIntAmt=NewPrin*MonthlyRate;
NewPrin=MonthlyIntAmt + HisAmt + NewPrin;
cout<<setw(4)<<months<<setw(10)<<MonthlyIntAmt<<setw(5)<<HisAmt<<setw(12)<<NewPrin<<endl;
}
cin.get();
}
I think you want the user to input the value for HisAmt, not MonthlyIntAmt. Right now, you're using HisAmt to calculate and output but it hasn't been initialized to a valid value.

1
2
cout<<"How much would you like to put away each month?";
cin>>HisAmt;


Then you may also want to round off the figures in the output so you just have two decimals for the dollar amounts.
Oh okay, wow I see my mistake now. I have been changing everything, but I didn't know it was that value I was missing. Thank you very much.
Last edited on
Topic archived. No new replies allowed.