# nested for loops and bank account interest help!!

• 04-07-2003
webvigator2k
nested for loops and bank account interest help!!
I've got a project where I have to use a NESTED for loop to calculate how much interest occurs at x% rate over x amount of years for an initial investment of \$1000. Trouble is, i dont understand how a for loop is going to do this for me. (keep in mind, im a newbie, my teacher is not very good and for loops are my weakest)

year 1 year 2 year 3 year 4 year 5

6%:
7%: THE ACTUAL ACCOUNT BALANCE DATA SHOULD APPEAR
8%: IN HERE NICELY FORMATTED
9%:
10%:
11%:
12%:

It's gotta appear in that format. Now, the formula (for the first one, accruing interest monthly) would be amt = (amt * (.06/12)) + amt. The outter loop would be something like (count = 0; count <= 7; count++)

inner loop for (count = 0; count <= 5; count++)

now where would i put the actual calculation of the interest and stuff? I tried this method with no avail (not to mention an infinite loop):

#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{

float intrate, amt;
int count;

intrate = .06/12;
amt = 1000;

for(count = 0; count <= 7; count++){

for(count = 0; count <= 5; count++)
amt = (amt * intrate) + amt;
}

cout << amt << endl;

system("pause");
return 0;
}
• 04-07-2003
Codeplug
You don't want to use the same variable in a double for loop. Read your book, run and study this code to try and get a handle on things:
Code:

```    int a,b;     for (a = 0; a < 5; a++)     {         for (b = 0; b < 5; b++)         {             cout << "a = " << a << " , b = " << b << endl;         }         cout << endl;     }```
gg