-1
Guys, I need help with the sum of variables in a struct. the program does not compile and displays this error [Error] request for Member 'salario' in Something not a Structure or Union. The objective is to add the values entered by the user in the salary field.
#include <stdio.h>
#include <stdlib.h>
struct funcionario
{
char nome[40];
float salario;
};
struct funcionario cad_func[2];
int main(void) {
int i;
printf("INSIRA SEUS DADOS.\n\n\n");
for(i=0; i<2; i++)
{
printf("nome: ");
fflush(stdin);
gets(cad_func[i].nome);
printf("salario: ");
scanf("%f", &cad_func[i].salario);
printf("\n\n");
}
system("cls");
printf("------------SEGUE ABAIXO NOME E SALARIO------------\n\n");
for(i=0; i<2; i++){
printf("Nome: %s\n", cad_func[i].nome);
printf("Salario: %f\n\n\n", cad_func[i].salario);
}
float totalSalario;
totalSalario = cad_func.salario[0] + cad_func.salario[1];
printf("Total: %f", totalSalario);
return 0;
}
Thank you!