Have an issue with some for statements.
I must be missing somew logic here. I'm trying to get this compound interest program going. I can get it to go through 10 years on one interest rate, but when I throw in the second for statement to try to get that same output, but for varying interest rates it does not do as planned. In fact I somehow get 11%
Code:
#include <stdio.h>
#include <math.h>
int main()
{
double amount;
double principal = 1000.0;
double rate = .05;
int year;
for ( rate = .05; rate <= .10; rate += .01 ) {
printf( "%4s%21s\n", "Year", "Amount on deposit" );
for ( year = 1; year <= 10; year++ ) {
amount = principal * pow( 1.0 + rate, year );
printf( "%4d%21.2f\n", year, amount );
}
}
return 0;
}