I'm trying to create a program that will find the final balance using interest rates.
For example, if a person has an initial balance of $2.19 and its interest compounded monthly for 3 months.
To get the final balance, the formula would be:
[2.19 + ((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03)]
** the .03 is the interest rate (3%) **
As you notice "
((1/12) * 2.19 * .03)" is used 3 times because it is being compounded monthly 3 times, this will be your total interest increase, then you add it to the initial balance which is 2.19.
((1/12) * 2.19 * .03) = ((1/12) * theInitialBalance * interestRate1)
Here is my attempt at this calculation, however, I'm getting no success.
1 2 3 4 5 6 7
|
calculateInt1 = ((1/12) * theInitialBalance * interestRate1);
for (int j = 1; j <= numberMonths; j++)
{
calculateInt1 = calculateInt1 + calculateInt1;
}
finalBalance = calculateInt1 + theInitialBalance;
cout << finalBalance << endl;
|
I definied the
((1/12) * 2.19 * .03) as calculateInt1, then what I'm hoping I got right was the adding part inside the loop, I'm trying to make the
((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03) + ((1/12) * 2.19 * .03). Then I would calculate the finalBalance by getting the total of calculateInt1 and adding that to the initialBalance (2.19).
However, this does not work, the output (finalBalance) is 2.19, it should be 2.21.
I'm just not 100% certain on the line within the for-loop, I feel like it is wrong, could someone explain what I should do instead?