Thread: nested for loops and bank account interest help!!

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    7

    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;
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bank Account Problem
    By JayBlay77 in forum C++ Programming
    Replies: 1
    Last Post: 03-19-2009, 08:41 AM
  2. Replies: 12
    Last Post: 06-03-2005, 01:13 AM
  3. Bank Account
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 09-14-2003, 02:27 AM
  4. Simple Bank Account Uni Project Help!!!
    By griff in forum C Programming
    Replies: 3
    Last Post: 05-09-2003, 05:49 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM