How can I write this Objective C program correctly? [closed]
In need some help with this little programming .. I just got 3 errors ..
:'(
**[
#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;
}
]**
You must give it a size like 3 (it can be any integer though) or something:
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.
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...
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.
As other said: read the error messages you get and think about what they could mean.
精彩评论