1. ## Compound Interest?

I have been trying for many hours to get this to work, but alas no success. i have about 6 programs to write and they all build off of this one so I'm stuck. I could really use some help please. this is my first post btw in case I am missing some sort of forum guidelines.

here is the program scenario:

Suppose you invest \$100.00 at an interest rate of 10% per year. The interest is computed at the end of each year, and is added to your account (i.e., the interest is compounded yearly). Print what the account value will be each year for 20 years. Use data type double. Do not use the pow function.

This is what I have so far:
Code:
```/* 20 yr interest */
#include <stdio.h>

/* function main begins program execution */
int main( void )
{
double amount;
double amount2;
double principal = 100.00;
int year;
double rate = .10;

printf("Year\tAmount on deposit (\$)\n");

for(year=1; year<=20; year++)
{
amount = principal * rate;
amount2 = (amount + principal) * rate;

printf("%4d\t\t%8.2lf\n", year, amount2);
}

return 0; /* indicate that program ended successfully */

} /* end function main */```

2. Code:
```/* 20 yr interest */
#include <stdio.h>

/* function main begins program execution */
int main( void )
{
double amount;
double amount2;
double principal = 100.00;
int year;
double rate = .10;

printf("Year\tAmount on deposit (\$)\n");
amount=principal;

for(year=1; year<=20; year++)
{
amount = amount * rate;
amount2 = (amount + principal) * rate;
amount=amount2;

printf("%4d\t\t%8.2lf\n", year, amount2);
}

return 0; /* indicate that program ended successfully */

} /* end function main */```
Have a look at this one.

3. It would be beneficial if you worked out - on paper - how you would compute the interest and (new) principal for each year BEFORE writing code.

I'll give two hints in the form of questions: why are you multiplying amount2 by rate? And why are you not updating principal each time through the loop?

4. Originally Posted by grumpy
why are you multiplying amount2 by rate?
My correction misses that one too.

5. Try ...

Code:
```for (int x = 0; x < years; x++ )
{ Principle += (Principle * Rate);
printf(" Year %d = %.2f \n", x + 1, Principle); }```

6. awesome i finally got it. thanks for all the help. i think i'm getting burnt out. anyway, i used:

Code:
```   double principal = 100.00;
int year;
double rate = .10;

printf("Year\tAmount on deposit (\$)\n");

for ( year = 1; year <= 20; year++ )
{ principal += (principal * rate);
printf(" %d\t\t%.2f \n", year, principal); }```

7. So ... ... be sure to let me know how I did on your homework...