Problem with float vector

1

I created a code for a college exercise that was running right, but I forgot that one of the variables of struct was a vector, and when I made a simple change everything changed. Virtually all functions are giving error. I do not find the answer anywhere.

BEFORE (when it worked) looked like this:

struct turma{
  int matricula;
  char nome[15];
  float nota;
  float media;
  char resultado;
}; typedef struct turma turma;

Then I changed to:

struct turma{
  int matricula;
  char nome[15];
  float nota[5];
  float media;
  char resultado;
}; typedef struct turma turma;

And nothing else works. Here is the example of a function that started to give error:

void insere (turma alg[MAX])
{   int x,y;
float cont=0;
for (x=0;x<MAX;x++)
{   printf("\nInforme os dados do %iº aluno: ", x+1);
    printf("\n\nMatrícula: ", x+1);
    scanf("%d", &alg[x].matricula);
    printf("Nome: ", x+1);
    fflush(stdin);
    scanf("%s", &alg[x].nome);
        for (y=0;y<5;y++){
        printf("%iº nota: ", y+1);
        scanf("%f", &alg[y].nota);
        cont = cont + alg[y].nota;
    }
}
}

The error of the last line is an error:

  

invalid operands to binary + (have 'float' and 'float *')

    
asked by anonymous 19.06.2015 / 05:41

1 answer

4
The problem is that you are trying to make a sum of a float % variable with a pointer (cont) .

Remember that you have modified your struct so that the variable becomes a float vector. Modify your code snippet to:

scanf("%f", &alg[x].nota[y]);
cont = cont + alg[x].nota[y];

I believe this will solve your problem

    
19.06.2015 / 08:03