急求一道c++改错题

来源:百度知道 编辑:UC知道 时间:2024/05/26 23:03:59
#include<iostream.h>
#define n 8
int fun(float *s,int n,float aver)
{ float t=0.0;
int count=0,k,i;
for (k=0;k<n;k++)
t+=s[k];
aver=t/n;
for(i=0;i<n;i++)
if (s[i]<aver) count++;
return count;
}
void main(){
float s[]={80.5,60 , 72, 90.5, 98, 51.5, 88, 64};
float aver=0;
int count=fun(s,n,aver);
cout<<"the average score is "<<aver<<" count="<<count<<endl;
}

提示
:\Documents and Settings\Student\桌面\42.cpp(3) : error C2143: syntax error : missing ')' before 'constant'
C:\Documents and Settings\Student\桌面\42.cpp(3) : error C2143: syntax error : missing ';' before 'constant'
C:\Documents and Settings\Student\桌面\42.cpp(3) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
只能改子

#include<iostream>
#define n 8
int fun(float *s,int m,float aver)
{ float t=0.0;
int count=0,k,i;
for (k=0;k<m;k++)
t+=s[k];
aver=t/m;
for(i=0;i<m;i++)
if (s[i]<aver) count++;
return count;
}
void main(){
float s[]={80.5,60 , 72, 90.5, 98, 51.5, 88, 64};
float aver=0;
int count=fun(s,n,aver);
std::cout<<"the average score is "<<aver<<" count="<<count<<std::endl;
}

程序清单:
#include<iostream>
using namespace std;
const n=8;

int fun(float *s,int n,float *aver)
{
float t=0.0;
int count=0,k,i;
for (k=0;k<n;k++)
t+=s[k];
*aver=t/n;

for(i=0;i<n;i++)
if(s[i]<*aver) count++;
return count;
}
void main()
{
float s[]={80.5,60 , 72, 90.5, 98, 51.5, 88, 64};
floa