需要一些帮助这个小编程..我只有3个错误..
:'(
** [
#include <stdio.h>
int main (void)
{
char A , B , C , D , E , F;
float id1[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float grade[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float marks[]; <<< *Definition of variable with array type needs an explicit size or an initializer*
float average;
float num1, kk=0;
/********* Jami, Abdulrahman *********/
printf("Enter The Student ID: ");
scanf("%d", &num1);
for (kk=0; kk<num1; kk++);
{
scanf("%d", &id1[kk]);
scanf("%d", &grade[kk]);
}
for (kk=0; kk<num1; kk++);
{
if (grade [kk]>85 &grade [kk]<=100);
A=A+1;
if (grade [kk]>70 &grade [kk]<85);
B=B+1;
if (grade [kk]>55 &grade [kk]<70);
C=C+1;
if (grade [kk]>40 &grade [kk]<55);
D=D+1;
if (grade [kk]>25 &grade [kk]<40);
E=E+1;
if (grade [kk]>=0 &grade [kk]<25);
F=F+1;
}
/********* Jami, Abdulrahman *********/
float aveerage;
float avrg, sum, lk;
sum = sum + marks[lk];
average = sum / num1;
for (lk=0; lk<num1; lk++);
return average;
}
] **
答案 0 :(得分:5)
你必须给它一个像3的大小(它可以是任何整数)或者其他东西:
例如:
float id1[];
//Should be:
float id1[3]; //Or whatever number you want.
或者你可以这样做:
float id1[] = { 0, 0, 0 }; //To get the same effect as id1[3] where they would all be initialized at zero.
甚至更好:
float id1[3] = { }; //Initialize all 3 elements to zero.
答案 1 :(得分:2)
错误告诉您需要在这些数组上设置大小。尝试将它们定义为float myArray [maxMarks]; 当然,maxMarks是最大标记数,而不是最高标记......
答案 2 :(得分:1)
尝试类似
的内容float *id1;
或
float id1[100];
或
float id1[] = { 1.0, 2.0, 3.3, 7.2, 9.1, 1.5, 4.1 };
如果使用值初始化数组,则[]只能为空。如果使用float *id1;
,则必须使用malloc()内存才能使用它。另外两个是真正的数组。
正如其他人所说:阅读你得到的错误信息并思考它们可能意味着什么。