formatted output

I would like to format my output so that it looks like this:


Head Movement             Tracks traversed
15 - 4                    11
4 - 40                    36


..........................and so on.
Here is my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	int count = _count;
	int current_track = 15;
	int tracks_traveled = 0;
	
	// Format the output
	cout.setf(ios::left);
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout << setw(25) <<"Head Movement" << setw(16) << "Tracks traversed" << endl;
	for (int i = 0; i < count; i++)
	{
		tracks_traveled += abs(current_track - queue[i]);
		cout<<setw(25)<<current_track<<" - "<< queue[i]<<setw(16)<< (abs(current_track - queue[i])) << endl;
		current_track = queue[i];
	}
	cout <<"\n" << endl;
	cout << setw(25) <<"Total tracks traversed" << setw(16) << tracks_traveled << endl;

}


Instead my output is like this:

Head Movement             Tracks Traversed
15                        - 411
4                         - 4036


..................and so on
What am I doing wrong?
try to remove setw(25) from for loop?
no, that doesn't seem like it would do it. It seems like it is an error in how I have setup the width of the fields. I was under the understanding that all of the text following the setw() would be in that field, until another field width was specified. I guess I was wrong.

Any other ideas as to how I could fix that?
use gotoxy(int X,int Y) function you can easily display as you like here is link for source code for gotoxy
http://codeincodeblock.blogspot.com/2011/03/gotoxy-in-codeblock.html
Topic archived. No new replies allowed.