我正在编写在C ++中不使用pow()的代码,但是我遇到了很多我无法弄清楚的错误:

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;
    }
}


错误:

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'


任何帮助,将不胜感激,谢谢。

最佳答案

它应该是for (i = 1; i <= N; i++)
在C ++中,使用分号分隔for循环的不同部分。

关于c++ - 在C++中为电源模块编写代码,收到一些错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14758709/

10-11 22:42
查看更多