Original Post
I'm writing a little program to figure out how much money you'll have after x years with x amount of interest. It's not working right though, I think my for loop is screwed up, it's supposed to run the code inside the loop once for each year (so if it's for four years, the loops is supposed to run four times.) For some reason though, it always gives me the answer for only one year of interest and not four.
Can someone take a loop at my crappy code and tell me what I did wrong. Thanks!
#include <stdio>
using namespace std;
int main()
{
float initamount,
interest,
total;
int numyears;
cout << "What is the initial amount? ";
cin >> initamount;
cout << "How many years? ";
cin >> numyears;
cout << "What is the interest per year? ";
cin >> interest;
for (int j = 1; j >= numyears; j++)
{
total = initamount + (initamount * interest / 100);
}
cout << "The total after " << numyears << " is "
<< total << '\n';
return 0;
}
Gary the Llama
[edited by - Gary the Llama on June 5, 2002 3:12:38 PM]