Results error. Cant determine if it's my formula or my function. please help!

Please help. My results are wayyyy off. If you put in 10 for the rate and 36 for the period... it's waaayyy off. I feel like I'm looking right at it and just dont see the issue. many many many thanks.

#include <iostream>
#include <cmath>
#include "COMPFUN.H"
using namespace std;

const double presentValue = 1000.00;
double futureValue(double presentValue, double rate, int n)
{
double result;
result = presentValue * pow(( rate + 1), n);
return result;
}

int main()
{
double rate;
int n;
double future_value;

cout << "Enter the percentage rate: ";
cin >> rate;
cout << "Enter the period in months: ";
cin >> n;

future_value = futureValue(presentValue, rate, n);
cout << "Future Value = " << future_value << endl;

system("pause");

return 0;

}
The values are OK if you are working for the mob. You have a rate of 1000% per month. If you want to input the annual percentage use
result = presentValue * pow(( rate*0.01 + 1), n/12);

Also, try not to use global variables (presentValue). Better to declare it in the main function, otherwise in future value function is not clear that you use the global presentValue, or the presentValue that you pass to the function
ok, thanks I got it now. What if i wanted to do a test driver on this...for the three percentages?
hi, i have one question for you mr.Garrett05:
aren't you have an "out of range" problem in the futurevalue() ??
i made some calculations and i happened to find that you're trying to store a really large number in the "result" variable:
the value of pow((rate+1),n) is like 11^36 , and a double can only store a 64bit number, so with some calculations you find that 11^36>x>2^64.
that's bigger than double can handle, i wonder!!!.
Topic archived. No new replies allowed.