请教一个c++的小问题
请问这个程序里面如果要将平均分的结果保留两位小数的话cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
要把这三行放在哪里?谢谢
程序为:
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
ifstream in_stream;
ofstream out_stream;
in_stream.open("infile.txt");
if(in_stream.fail())
{
cout<<"input file opening failed.\n";
exit(1);
}
out_stream.open("outfile.txt");
if(out_stream.fail())
{
cout<<"output file opening failed.\n";
exit(1);
}
int first,second,third,fourth,fifth,sixth,seventh,eighth,nineth,tenth;
double average;
average=(first+second+third+fourth+fifth+sixth+seventh+eighth+nineth+tenth)/10;
in_stream>>first>>second>>third>>fourth>>fifth>>sixth>>seventh>>eighth>>nineth>>tenth;
cout << first<< endl;
cout << second<< endl;
cout<< third<< endl;
cout<<fourth<<endl;
cout<<fifth<<endl;
cout<<sixth<<endl;
cout<<seventh<<endl;
cout<<eighth<<endl;
cout<<nineth<<endl;
cout << tenth<< endl;
out_stream<<"the average of the 10\n"
<<"number in infile.txt\n"
<<"is"
<<(first+second+third+fourth+fifth+sixth+seventh+eighth+nineth+tenth)
<<endl;
cout<<"the average is:"<<(first+second+third+fourth+fifth+sixth+seventh+eighth+nineth+tenth)/10<<endl;
in_stream.close();
out_stream.close();
return 0;
}