10x10 addition table tweeking

Ok, I have this code:

for (rows=0; rows < 11; rows++)
{
for (cols=0; cols < 11; cols++)
{
sum = rows + cols;
if (sum < 10) cout << " ";
cout << sum << " ";
}
cout << endl;
}

It does generate the addition table correctly. However, for my lab assignment, it cannot display that zero in the top left corner. Is there a way to easily manipulate that?
All variables are defined
Yes there is, rsh0117..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
for (int rows=0; rows < 11; rows++)
{
for (int cols=0; cols < 11; cols++)
{
sum = rows + cols;
if (sum < 10 )
cout << " ";
if (sum!=0) // If sum isn't 0, then sum and space printed
cout << sum << " ";
else
cout << "  "; // otherwise, just a space, to keep everything in line
}
cout << endl;
}
Topic archived. No new replies allowed.