table

ok i'm trying to build this table and have this so far

#include <iostream>
using namespace std;

int main()
{
int me;

int row;
int column;
int sum = 0;

for (row =1; row <= 12; row++)
for (column = 1; column <= 12; column++)
{
cout << row * column;

if ( column == 12 )
cout << endl;
else
cout << " ";

}

cin >> me;
return 0;
}

it outputs the multiplication, but its not aligned properly and i can't use setw. is there another way to align? i searched in my book and couldn't find anything. and also need headers for the row and columns, and whatever i try something, it messes up the table, any pointers?
[873 byte] By [shooter23000] at [2007-11-20 11:34:22]
# 1 Re: table
1. Please use code tags, whenever posting code ! Make sure your code is indented correctly.

2. Use setw in conjunction with left or right to do the alignment

3. Instead of the "if (column == 12)" part, you should write the linefeed outside of the inner loop (but inside the outer loop). That will make your program more readable.

4. You are flushing the output buffer after every row, which seems very unnessecary. Use "\n" instead of std::endl to put out linefeeds without flushing. (This might seem irrelevant for you now, but if you put out some thousands of lines, the performance difference is very significant)

Example for the loop: for (int row = 1; row <= 12; row++) {
for (int column = 1; column <= 12; column++) {
std::cout << std::setw(4) << std::right << row * column;
}
std::cout << "\n";
}
treuss at 2007-11-9 1:25:56 >
# 2 Re: table
thanks for the tips treuss
shooter23000 at 2007-11-9 1:26:53 >