# compounding interest

This is a discussion on compounding interest within the C++ Programming forums, part of the General Programming Boards category; Code below was supposed to display interest yearly. i.e: Year 1 \$1000 Year 2 \$1100 Year 3 \$1210 etc However, ...

1. ## compounding interest

Code below was supposed to display interest yearly. i.e:
Year 1 \$1000
Year 2 \$1100
Year 3 \$1210
etc

However, it's not doing that. It's listing the end year result in every year. What am I missing? My professor is inept and can't explain it to me. Any help would be greatly appreciated.

//compound interest
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
main()
{
int n;
float principle,rate,amount;
cout<<"This will determine the compound interest over the entered number "
<<"of years";
cout<<"Enter the principal: \$";
cin>>principle;
while (principle !=-1){
cout<<"Enter rate in decimals: ";
cin>>rate;
cout<<"Enter number of years: ";
cin>>n;
for(int year=1;year<=n;year++){
amount=principle*pow(1+rate,n);
cout<<"Year "<<year<<setw(12)<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint)
<<setprecision(2)<<"\$"<<amount<<endl;
}
cout<<"Enter principle or -1 to end: ";
cin>>principle;
}
return 0;

2. amount=principle*pow(1+rate,n);

in this n is a constant and 1+rate is a constant so no matter how many times thru the loop the end result is always the same. do you mean something like this :-

amount=principle*pow(1+rate,year);

3. ## wow... many thanx!

You are the man!