类型' int'的操作数无效。和' double(double *,double *,int)'到二元运算符

时间:2014-11-21 00:45:36

标签: c++ types binary operator-keyword operands

我们正在为课堂上的项目进行线性回归。我必须写一个函数。我已经尝试过静态转换和其他将“int n”更改为double的方法,因此它不会抛出错误?还是我完全错误的思路?

功能

void linear_regression(double x[], double y[], int n,
                   double *slope, double *y_int)
{    
    double sum_x, sum_y, sum_x_Squared, sum_Squared_x, product_x_y;
    double m = *slope, b = *y_int;

    sum_x = sum_array(x, n);
    sum_y = sum_array(y, n);

    sum_Squared_x = sum_square_array(x, n);
    sum_x_Squared = sum_array(x, n) * sum_array(x, n);

    product_x_y = sum_product_of_arrays(x, y, n);

    //I'm getting an error on the next statement, about the n
    m = ((sum_x * sum_y) - (n * sum_product_of_arrays)) /
            ((sum_x_Squared) - (n * sum_Squared_x));
    b = ((sum_y - (m * sum_x))/(n));

    return;
}

错误消息

Invalid operands of types 'int' and 'double(double*, double*, int)' to
binary operator.

1 个答案:

答案 0 :(得分:5)

n * sum_product_of_arrays中,sum_product_of_arrays是您调用以获取product_x_y的函数。您的意思是使用product_x_y吗?