邪恶动态图翘臀:c++中的一个小问题
来源:百度文库 编辑:神马品牌网 时间:2024/08/29 13:05:09
一个求15个浮点数之和及平均值的程序
# include <iostream.h>
double sum_double(double[]);
double average_double(double[]);
void main()
{
double a[15];
cout<<"请输入15个浮点数:";
for(int i=0;i<15;i++)
cin>>a[i];
double sum=sum_double(a);
double average=average_double(a);
cout<<"\n和为:"<<sum<<"\n平均值为:"<<average<<endl;
}
double sum_double(double m[])
{
double sum=0;
for(int j=0;j<15;j++)
sum+=m[j];
return sum;
}
double average_double(double n[])
{
double average,a;
a=sum_double(double n[]);
average=a/15;
return average;
}
为什么会有如下错误,请高手指点
\Cpp1.cpp(24) : error C2144: syntax error : missing ')' before type 'double'
\Cpp1.cpp(24) : error C2660: 'sum_double' : function does not take 0 parameters
\Cpp1.cpp(24) : error C2059: syntax error : ')'
# include <iostream.h>
double sum_double(double[]);
double average_double(double[]);
void main()
{
double a[15];
cout<<"请输入15个浮点数:";
for(int i=0;i<15;i++)
cin>>a[i];
double sum=sum_double(a);
double average=average_double(a);
cout<<"\n和为:"<<sum<<"\n平均值为:"<<average<<endl;
}
double sum_double(double m[])
{
double sum=0;
for(int j=0;j<15;j++)
sum+=m[j];
return sum;
}
double average_double(double n[])
{
double average,a;
a=sum_double(double n[]);
average=a/15;
return average;
}
为什么会有如下错误,请高手指点
\Cpp1.cpp(24) : error C2144: syntax error : missing ')' before type 'double'
\Cpp1.cpp(24) : error C2660: 'sum_double' : function does not take 0 parameters
\Cpp1.cpp(24) : error C2059: syntax error : ')'
24行 n 前不要加double,也不要用n[],直接改为
a=sum_double(n);