#include<stdio.h>
void ave_max_min(int b[10],int n);
int Max=0,Min=0;
int main()
{
int a[10],average;
for(unsigned int i =0;i<10;i++)
{
scanf(“%d”,&a[i]);
}
average = ave_max_min(a,10);
printf(“本班平均成绩为:%d\n本班最高分数为:%d\n本班最低成绩为:%d\n”,average,Max,Min);
}
void ave_max_min(int b[10],int n)
{
float average;
int sum=0;
unsigned int i =0;
Max = Min = b[i];
for(i=0;i<10;i++)
{
if(b[i]>Max)
{
Max=b[i];
}
else if (b[i]<Min)
{
Min=b[i];
}
sum += b[i];
}
average = sum / n;
}
编译器一直提示说[Error] C:\Users\lEECQ\Documents\C-Free\Temp\未命名35.cpp:11: error: void value not ignored as it ought to be
就是average = ave_max_min(a,10)那一行不知道出了什么问题…
void ave_max_min(int b[10],int n);
int Max=0,Min=0;
int main()
{
int a[10],average;
for(unsigned int i =0;i<10;i++)
{
scanf(“%d”,&a[i]);
}
average = ave_max_min(a,10);
printf(“本班平均成绩为:%d\n本班最高分数为:%d\n本班最低成绩为:%d\n”,average,Max,Min);
}
void ave_max_min(int b[10],int n)
{
float average;
int sum=0;
unsigned int i =0;
Max = Min = b[i];
for(i=0;i<10;i++)
{
if(b[i]>Max)
{
Max=b[i];
}
else if (b[i]<Min)
{
Min=b[i];
}
sum += b[i];
}
average = sum / n;
}
编译器一直提示说[Error] C:\Users\lEECQ\Documents\C-Free\Temp\未命名35.cpp:11: error: void value not ignored as it ought to be
就是average = ave_max_min(a,10)那一行不知道出了什么问题…
解决方案:20分
void ave_max_min(int b[10],int n); 返回值void
average = ave_max_min(a,10); 又有返回值
改成float ave_max_min(int b[10],int n); 试试,函数里面要有return
average = ave_max_min(a,10); 又有返回值
改成float ave_max_min(int b[10],int n); 试试,函数里面要有return