tags:

views:

49

answers:

1

I'm trying to write a code that calculates the approximate factorial of a number using Stirling's formula.

Here's the line that calculates it:

appFact = pow(exp, -num) * pow(num, num) * sqrt(2 * num * PI);

The error comes in at pow(exp, -num) with pow underlined in red.

IntelliSense: no instance of overloaded function "pow" matches the argument list 25

float num, num2, num3, num4, MEAN, stanDev, VARI, appFact, exp;

readFile >> num >> num2 >> num3 >> num4;

appFact = pow(exp, -num) * pow(num, num) * sqrt(2 * num * PI);

+2  A: 

Try including the appropriate header file:

#include <cmath>

If that doesn't help, note that the implementation of pow() is in the std namespace. So:

appFact = std::pow(exp, -num) * std::pow(num, num) * std::sqrt(2 * num * PI);
Greg Hewgill
Same problem; IntelliSense: no instance of overloaded function "std::pow" matches the argument list 26
Evan
So, what types are `exp` and `num`? That's the "argument list" the message is referring to.
Greg Hewgill
If you hadn't declared `exp` at all, you would have got a compiler error when you tried to compile your code. I wouldn't rely on IntelliSense to tell you about compiler errors; generally it works best when your code *already* compiles (mostly) correctly.
Greg Hewgill