如何正确编写此Objective C程序?

时间:2022-01-13 20:43:58

In need some help with this little programming .. I just got 3 errors ..

需要一些帮助这个小编程..我只有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;
}

]**

] **

3 个解决方案

#1


5  

You must give it a size like 3 (it can be any integer though) or something:

你必须给它一个像3的大小(它可以是任何整数)或其他东西:

For example:

例如:

float id1[];
//Should be:
float id1[3]; //Or whatever number you want.

Or you can do:

或者你可以这样做:

float id1[] = { 0, 0, 0 }; //To get the same effect as id1[3] where they would all be initialized at zero.

Or even better:

甚至更好:

float id1[3] = { }; //Initialize all 3 elements to zero.

#2


2  

The error tells you that you need to set a size on these arrays. Try defining them as float myArray[maxMarks]; Of course maxMarks is the maximal number of marks, not the highest mark...

该错误告诉您需要在这些数组上设置大小。尝试将它们定义为float myArray [maxMarks];当然maxMarks是最大的标记数,而不是最高标记......

#3


1  

Try something like

尝试类似的东西

float *id1;

or

要么

float id1[100];

or

要么

float id1[] = { 1.0, 2.0, 3.3, 7.2, 9.1, 1.5, 4.1 };

The [] can only be empty if you initialize the array with values. if you use float *id1;, you'll have to malloc() memory to use it. The other two are real arrays.

如果使用值初始化数组,则[]只能为空。如果使用float * id1;,则必须使用malloc()内存才能使用它。另外两个是真正的数组。

As other said: read the error messages you get and think about what they could mean.

正如其他人所说:阅读你得到的错误信息,并思考它们可能意味着什么。

#1


5  

You must give it a size like 3 (it can be any integer though) or something:

你必须给它一个像3的大小(它可以是任何整数)或其他东西:

For example:

例如:

float id1[];
//Should be:
float id1[3]; //Or whatever number you want.

Or you can do:

或者你可以这样做:

float id1[] = { 0, 0, 0 }; //To get the same effect as id1[3] where they would all be initialized at zero.

Or even better:

甚至更好:

float id1[3] = { }; //Initialize all 3 elements to zero.

#2


2  

The error tells you that you need to set a size on these arrays. Try defining them as float myArray[maxMarks]; Of course maxMarks is the maximal number of marks, not the highest mark...

该错误告诉您需要在这些数组上设置大小。尝试将它们定义为float myArray [maxMarks];当然maxMarks是最大的标记数,而不是最高标记......

#3


1  

Try something like

尝试类似的东西

float *id1;

or

要么

float id1[100];

or

要么

float id1[] = { 1.0, 2.0, 3.3, 7.2, 9.1, 1.5, 4.1 };

The [] can only be empty if you initialize the array with values. if you use float *id1;, you'll have to malloc() memory to use it. The other two are real arrays.

如果使用值初始化数组,则[]只能为空。如果使用float * id1;,则必须使用malloc()内存才能使用它。另外两个是真正的数组。

As other said: read the error messages you get and think about what they could mean.

正如其他人所说:阅读你得到的错误信息,并思考它们可能意味着什么。