关于precision()的输出问题,求解。
请大家看下下面的程序:输入
4
20070001 94 92 97 93 90
20070005 84 89 92 81 73
20070004 82 75 94 86 95
20070003 84 86 82 97 91
输出
20070001 94 92 97 93 90 93.2
20070005 84 89 92 81 73 83.8
20070004 82 75 94 86 95 86.4
20070003 84 86 82 97 91 88.0
86.0 85.5 91.3 89.3 87.3
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
double bb=0,cc=0,dd=0,ee=0,ff=0;
int main()
{
for(int n;cin>>n;)
{
for(int i=1;i<=n;i++)
{
string a;
double b,c,d,e,f,ave;
cin>>a>>b>>c>>d>>e>>f;
ave=(b+c+d+e+f)/5;
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" ";
cout<<fixed<<setprecision(1)<<ave<<endl;
bb+=b;cc+=c;dd+=d;ee+=e;ff+=f;
}
double q,w,e,r,t;
q=bb/n;
w=cc/n;
e=dd/n;
r=ee/n;
t=ff/n;
cout<<fixed<<setprecision(1)<<q<<" "<<fixed<<setprecision(1)<<w<<" "<<fixed<<setprecision(1)
<<e<<" "<<fixed<<setprecision(1)<<r<<" "<<fixed<<setprecision(1)<<t<<endl;
}
return 0;
}#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
double bb=0,cc=0,dd=0,ee=0,ff=0;
int main()
{
for(int n;cin>>n;)
{
for(int i=1;i<=n;i++)
{
string a;
double b,c,d,e,f,ave;
cin>>a>>b>>c>>d>>e>>f;
ave=(b+c+d+e+f)/5;
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<f<<" ";
cout<<fixed<<setprecision(1)<<ave<<endl;
bb+=b;cc+=c;dd+=d;ee+=e;ff+=f;
}
double q,w,e,r,t;
q=bb/n;
w=cc/n;
e=dd/n;
r=ee/n;
t=ff/n;
cout<<fixed<<setprecision(1)<<q<<" "<<fixed<<setprecision(1)<<w<<" "<<fixed<<setprecision(1)
<<e<<" "<<fixed<<setprecision(1)<<r<<" "<<fixed<<setprecision(1)<<t<<endl;
}
return 0;
}
但是我这样写的输出,后面几组的原始数据也变成了一位小数。。我setprecision()的用法哪儿错了吗????