c - 我在C程序中遇到冲突类型错误

标签 c linux function compiler-errors

我回到用C进行编程的过程中,尝试编译该程序时出现以下错误:

error: conflicting types for 'getMedia'


我没有找到下面的错误,首先我想这可能是类型错误,但事实并非如此,我试图将上面的函数声明为全局“变量”,但它不起作用。
有人可以帮我吗?

#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;
}

最佳答案

您必须先声明函数,然后才能使用它。
PS我已经删除了checkExam();因为没有给出功能

#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;
}
要么
#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");
    }
}

关于c - 我在C程序中遇到冲突类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63093857/

相关文章:

c - 使用 C 编程禁用 arduino 微 Controller 上的键盘

linux -/var/log/messages 中的错误编号是什么意思?

linux - Libcurl支持多播文件传输吗?

javascript - JS - 无法获取函数实例的构造函数名称

language-agnostic - 函数参数中 "res"的含义和用途是什么?

c - 将字符串数组作为参数传递给函数

c++ - 使用 Windows 共享内存共享小数据

function - PowerShell 模块设计 - Export-ModuleMember

c - 将 int 存储在 char* 中 [C]

c++ - 接收数据包发送后,等待功能等待