I am having problems creating a simple table. I am using setw() but the dividers for the table are not staying still when you cout the name and age. What am I doing wrong? I also found a way to sort the ages from greatest to smallest but I don't know how to attach the names to the ages but thats a different prob. Thanx!
cpp
cout << "|" << name1 << setw(20)<<" | " <<setw(5)<<age1 << setw(5)<<" |"<<endl;
cout << "|" << name2 << setw(20)<<" | " <<setw(5)<<age2 << setw(5)<<" |"<<endl;
cout << "|" << name3 << setw(20)<<" | " <<setw(5)<<age3 << setw(5)<<" |"<<endl;
cout << "|" << name4 << setw(20)<<" | " <<setw(5)<<age4 << setw(5)<<" |"<<endl;
cout << "|" << name5 << setw(20)<<" | " <<setw(5)<<age5 << setw(5)<<" |"<<endl;
I should look like this.
(Of course with different names and ages.)
| William Penn | 23 |
| William Penn | 23 |
| William Penn | 23 |
| William Penn | 23 |
| William Penn | 23 |
Instead this is what I get....
(Without the dots, had to put them in to show how it skips spaces)
| William Penn ............| 23 |
| William Penn |...........23 |
| William Penn | 23............|
| William Penn |....... 23 .....|
| William Penn........| 23 |
This post has been edited by overclocked: 12 Mar, 2008 - 01:14 PM