0

I've created a code to calculate my class notes, it was working the first time, but after some runs, it shows:

[Error] variable-sized object may not be initialized

I don't know why! :(

CODE:

    system("Color Fs");
    float total = 0, moyenne;
    int i,j, mawad = 11, ghanat = 3;
    char * NAMES[] = {"Archi", "Dev", "EEJ", "ENG", "AR", "FR", "MATH", "RESEAU", "LINUX", "WIN", "TEC"};
    
    float NOTES[mawad][ghanat] =
    {
        {20, 0, 0},
        {20, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {15, 0, 0},
        {35, 0, 0},
        {30, 0, 0},
        {30, 0, 0},
        {10, 0, 0},
    };
    
    printf("------------------------------ LAY YSBR LGAMI3 ------------------------------\n");
    
    for (i=0;i<mawad;i++){
        printf("DGHL NO9TA DYAL %s", NAMES[i]);
            for (j=0;j<2;j++) {
                do {
                    printf("\t\tFRD %d:\n", j+1);
                    scanf("%f", &NOTES[i][j+1]);
                } while (NOTES[i][j+1] > 20); // ILA DGHL KTR MN 20;
            }
        total += ((NOTES[i][1] + NOTES[i][2]) / 2) * NOTES[i][0];
    }
    
    moyenne = total / 200;
    printf("\n\tMoyenne: %.3f \n", moyenne);
Saif Manwill
  • 692
  • 1
  • 9
  • 20
  • see [error: variable sized object may not be initialized](https://stackoverflow.com/questions/3082914/c-compile-error-variable-sized-object-may-not-be-initialized) you can't initialize NOTES array with a variable. Either put a number, or declare mawad and ganat as const. – Karthik Sriram Feb 13 '21 at 16:21
  • OOOh fixed but it was working with variable the first time hhh? – Saif Manwill Feb 13 '21 at 16:29
  • It's hard to guess when we don't know what changed between the code from before and now but perhaps you used constants directly in the array declaration, or maybe the number was small enough that the array could be initialized. At any rate, we can't say without more info – Karthik Sriram Feb 13 '21 at 16:37

1 Answers1

0

To fix that we need to add values directly:

float NOTES[11][3] =
    {
        {20, 0, 0},
        {20, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {10, 0, 0},
        {15, 0, 0},
        {35, 0, 0},
        {30, 0, 0},
        {30, 0, 0},
        {10, 0, 0},
    };
Saif Manwill
  • 692
  • 1
  • 9
  • 20