Quote:
10.395 (in this case, WHY is the value higher than 10??? I mean, I put in the code:
money <= money2, so why is it higher?)
Because at the end of year 14 you 've got slightly less than $10 and at the end of year 15 you have slightly more than $10. You
Quote:
And the other thing is, why is x (the years) always 15?? if input 2, the output is the same: 15, and if i put 1000 its again 15.
It doesn't matter if you invest $1 or $1000. Your investment will double in 15 years.
Quote:
You could make use of a formula for calculating compound interest. Doing some simple manipulation of a formula shown on Wikipedia, I derived:
n = log(f / p) / log(1 + i)
where n is the number of periods (years in your case), f is the future value, p the present value, and i the interest rate. log() is available in <cmath>.
Assuming this is a homework assignment (or exercise) having to do with loops, I wouldn't recommend using a financial formula "shortcut". If it's a real-world fincancial application I would NOT use a loop.