spacing all wrong

ive been working at this for a while. any ideas how to fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void display(char sudokuBoard[][9])
{
   //Declare variables
   char option;

   //Display Column Header
   cout << "   A B C D E F G H I" << endl;
   
   for (int y = 0; y<9; y++)
   {
       cout << y << "  ";
   if ((y / 9) != 0 && (y / 9) % 3 == 0)// && (y % 9) == 0)
       cout<<"-----+-----+-----\n";
   for (int x = 0; x<9; x++)
       {   
       if ((x % 9) != 0 && (x % 9) % 3 == 0)
        cout << "|";
       if (x%3)
           cout<<" ";
   cout << sudokuBoard[x][y];
       }
  cout << endl;
}



it looks like this right now.


   A B C D E F G H I
0  7 2 3|     |1 5 9
1  6    |3   2|    8
2  8    |  1  |    2
3    7  |6 5 4|  2
4      4|2   7|3
5    5  |9 3 1|  4
6  5    |  7  |    3
7  4    |1   3|    6
8  9 3 2|     |7 1 4



to this

   A B C D E F G H I
1  7 2 3|     |1 5 9
2  6    |3   2|    8
3  8    |  1  |    2
   -----+-----+-----
4    7  |6 5 4|  2
5      4|2   7|3
6    5  |9 3 1|  4
   -----+-----+-----
7  5    |  7  |    3
8  4    |1   3|    6
9  9 3 2|     |7 1 4
To make the row numbers correct print (y + 1) instead of y.


1
2
if ((y / 9) != 0 && (y / 9) % 3 == 0)
	cout<<"-----+-----+-----\n";
This doesn't seem to be right. (y / 9) != 0 is equivalent to y > 9 in this case. That never happens so it will never print the line. What you want is probably something like if ((y % 3) == 0 && y > 0). Also, print this line before you print the row number.

Last edited on
Looks like you also want cout<<"\n-----+-----+-----\n";
ya...I fixed it all. ITs solved...well this part is. It looks like thisoks like this

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
void display(char sudokuBoard[][9])
{

   char option;

   cout << "   A B C D E F G H I" << endl;

   for (int y = 0; y < 9; y++)
   {
      if ((y % 3) == 0 && y > 0)
         cout << "   -----+-----+-----\n";
      cout << y + 1 << "  ";

      for (int x = 0; x < 9; x++)
      {
         if ((x % 9) != 0 && (x % 9) % 3 == 0)
            cout << "|";
         if (x % 3)
            cout << " ";
         cout << sudokuBoard[x][y];
      }
      cout << endl;
   }
   cout << endl;
   getOption(sudokuBoard);
}
Topic archived. No new replies allowed.