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.
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.