0

I was returning to programming in C, and I get this error when I was trying to compile the program:

error: conflicting types for 'getMedia'

I'm not finding the error below, first i was thinking that could be a type error, but is not the case, I've tried to declare the function above as global 'variable' but it not work.

Could someone help me?


#include <stdio.h>
#include <stdlib.h>

int main()
{

    float nota1,nota2,nota3,nota4;
    scanf("%f %f %f %f",&nota1,&nota2,&nota3,&nota4);
    float media = getMedia(nota1,nota2,nota3,nota4);
    if(media < 5.0 && media >= 0){
        printf("Aluno reprovado\n");
    }else if(media > 7 && media <= 10){
        printf("Aluno aprovado\n");
    }else{
        checkExam();
    }
}

float getMedia(float nota1,float nota2, float nota3, float nota4){
    return (nota1*2+nota2*3+nota3*4+nota4)/10;
}

  • 1
    Does this answer your question? [Getting "conflicting types for function" in C, why?](https://stackoverflow.com/questions/1549631/getting-conflicting-types-for-function-in-c-why) – Adrian Mole Jul 25 '20 at 22:31

1 Answers1

1

You have to declare the function before using it. PS I have removed checkExam(); as the function is not given

#include <stdio.h>
#include <stdlib.h>

float getMedia(float nota1,float nota2, float nota3, float nota4);

int main()
{

    float nota1,nota2,nota3,nota4;
    scanf("%f %f %f %f",&nota1,&nota2,&nota3,&nota4);
    float media = getMedia(nota1,nota2,nota3,nota4);
    if(media < 5.0 && media >= 0){
        printf("Aluno reprovado\n");
    } else if(media > 7 && media <= 10){
        printf("Aluno aprovado\n");
    }
}

float getMedia(float nota1,float nota2, float nota3, float nota4){
    return (nota1*2+nota2*3+nota3*4+nota4)/10;
}

or

#include <stdio.h>
#include <stdlib.h>

static float getMedia(float nota1,float nota2, float nota3, float nota4){
    return (nota1*2+nota2*3+nota3*4+nota4)/10;
}

int main()
{

    float nota1,nota2,nota3,nota4;
    scanf("%f %f %f %f",&nota1,&nota2,&nota3,&nota4);
    float media = getMedia(nota1,nota2,nota3,nota4);
    if(media < 5.0 && media >= 0){
        printf("Aluno reprovado\n");
    }else if(media > 7 && media <= 10){
        printf("Aluno aprovado\n");
    }
}
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Ôrel
  • 7,044
  • 3
  • 27
  • 46