gpt4 book ai didi

c - 函数调用错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:24 24 4
gpt4 key购买 nike

在终端中编译这段代码时,我收到一条错误消息:

newfile1.c:17: error: conflicting types for ‘average’
newfile1.c:2: note: previous declaration of ‘average’ was here

我看不出代码有什么问题。有人可以帮帮我吗?

enter code here
#include<stdio.h>
float average(float);
int main()
{
float marks[4],avg;
int i;
printf("Please enter your marks\n");
for(i=0;i<=3;i++)
{
scanf("%d",&marks[i]);
}
avg = average(marks[4]);
printf("The average marks value is %f",avg);
return 0;
}



float average(float a[4])
{
int i,sum;
float avg_m;
for(i=0;i<=3;i++)
{
sum=sum+a[i];
}
avg_m=sum/3;
return avg_m;
}

最佳答案

替换

float average(float);

float average(float[]);

函数声明和定义不匹配。

然后像这样调用函数:

avg = average(marks);

关于c - 函数调用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com