I’m writing code that doesn’t use pow() in c++, but I am getting quite a few errors which I can’t figure out:
double power (double X, unsigned int N)
{
double value;
unsigned int i = 1;
for (i = 1, i <= N, i++)
{
result = result * X;
}
if (finite(result))
{
return result;
}
else
{
return INFINITY;
}
}
Errors:
In function 'double power(double, unsigned int)':
Line 5: warning: right-hand operand of comma has no effect
Line 5: error: expected ';' before ')' token
Line 10: error: expected primary-expression before 'if'
Line 10: error: expected ';' before 'if'
Line 10: error: expected primary-expression before 'if'
Line 10: error: expected ')' before 'if'
Any help would be appreciated, thanks.
It should be
for (i = 1; i <= N; i++).In C++, the semicolon is usd to delimit the different parts of the for loop.