为什么我收到错误消息,在'for'之前应收到非限定 id

Why am I getting the error message, expected unqualified id before 'for'

本文关键字:id for 消息 为什么 错误      更新时间:2023-10-16

我必须为大学作业编写一个这样的代码。我已经编写了代码的平均函数,但我收到了另一个函数的错误消息。DEVBARD_read加速计功能将读取加速度的x、y、z分量

首先,您需要编写一个函数:int average(int*array,int nLen(;其返回整数值数组的平均值。(为了防止溢出,建议使用长的内部变量(。精神等级功能将运行一个循环。对于每次迭代,重力加速度的Z分量将以50ms的间隔采样四次,并存储在适当大小的阵列中。使用您编写的average((函数,确定平均值并分析

int average(int* array, int nlen) {  // assuming array is int
long sum = 0L;  // sum will be larger than an item, long for safety.
for (int i = 0; i < nlen; i++) {
sum += array[i];
}
return ((long)sum) / nlen;
}
float sum[3];
int j;
for (int j = 0; j < 3; j++) {
i = DEVBOARD_readAccelerometer(int* xAccel, int* yAccel, int* zAccel);
sum[j] = int * zAccel;
}
average(float* sum[j], float nlen);
printf("The average zcomponent is %fn");
}

unqualified-id before for

您声明了变量j两次。在for循环的之前有一个,在for定义的内有一个。