hype261 is right about 'Sery', but the situation is a little more confusing in 'Pow'.
- double Pow(double x, int n)
-
{
-
if (n == 0)
-
return 1;
-
if (n > 0)
-
return x * Pow(x, n - 1);
-
if (n < 0)
-
return Pow(1 / x, -n);
-
}
The compiler is worried that the last
if test might be false, causing execution to fall out of the function without hitting a
return statement. You might argue that the previous two
if statements guarantee that the last test can't be false, but your compiler is unable to recognize this dependency between these statements.
The following alternative will satisfy the compiler:
- double Pow(double x, int n)
-
{
-
if (n == 0)
-
return 1;
-
else if (n > 0)
-
return x * Pow(x, n - 1);
-
else /* n must be < 0. */
-
return Pow(1 / x, -n);
-
}
By the way, you might want to change the name of your 'Pow' function so that it won't be confused with the Standard Library 'pow' function.