How do I correctly organize output into columns?
http://s1281.photobucket.com/user/anhkha1205/media/alignment_zps92baad39.png.html
check the link for the picture.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
int main()
{
double x[20],y[20], c[20], total_c;
int i;
total_c=0;
ifstream indata("footballstats.txt");
cout<<"i A[i] B[i] C[i] "<<endl<<endl;
for (int i=0;i<=19;i++)
{
indata >> x[i] >> y[i];
c[i]= x[i]*y[i];
cout<<""<<i;
cout<<setw(10)<<"A["<<i<<"] = "<<x[i];
cout<<setw(10)<<"B["<<i<<"] = "<<y[i];
cout<<setw(10)<<"C["<<i<<"] = "<<c[i]<<endl;
// cout<<setw(2)<<x[i]<<setw(15)<<y[i]<<setw(15)<<c[i]<<endl;
total_c = total_c + c[i];
}
cout<<endl<<"Total C: "<<total_c<<endl<<endl;
system("pause");
return 0;
}
|
Maybe something like this:
1 2 3 4 5
|
cout << setw(2) << i
<< setw(10) << x[i]
<< setw(18) << y[i]
<< setw(20) << c[i]
<< endl;
|
|
cout << "\t"; //c++'s interpretation of a tab
|
Topic archived. No new replies allowed.