I have an assignment for my C++ class that ask me to calculate the future investment value using a function prototype:
futureInvestmentValue = initialDeposit * (1 + monthlyInterestRate)^(years*12)
The problem is I keep getting inf as my output, whereas the correct output should be 1032.99. Why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <cmath>
usingnamespace std;
double futureInvestmentValue(double initialDeposit,
double monthlyInterestRate, int years);
int main () {
cout<<futureInvestmentValue(1000, 3.25/100/12, 12);
return 0;
}
double futureInvestmentValue (double initialDeposit,
double monthlyInterestRate, int years)
{ double result;
result= pow(initialDeposit*(1+monthlyInterestRate),(years*12));
return result;
}
Your result formula does not match the formula at the beginning of your post.
You want to have initialDeposit outside of the pow() function, not as part of the base.
Edit: Also, the number in the exponent is usually in years for formulas like this, you probably don't want to multiply it by 12.