# Thread: Numbers inside grid box help

1. ## Numbers inside grid box help

Ok so my professor wants us to produce binary numbers in the grid box that I just made. I am not sure how that works. The only hint he gave us is that it requires an if command and it should work for 3 digit numbers as well since my grid box is not fixed. Where would I implement that if I want to produce a binary number for each cell? By the way I'm working with a 4 x 4 grid table
Code:
```void GridBox(int Row,int Col,int SizeX, int SizeY, int Color)
{
int q,k,m;
char UpperLeft[2],UpperRight[2],LowerLeft[2],LowerRight[2];
char Vertical[2],Horizontal[2];
char UpperTee[2],LowerTee[2],LeftTee[2],RightTee[2];
char Cross[2];

_settextcolor(Color);

UpperLeft [0] = 218;
UpperRight[0] = 191;
LowerLeft [0] = 192;
LowerRight[0] = 217;
Vertical  [0] = 179;
Horizontal[0] = 196;

UpperTee[0] =   194;
LowerTee[0] =   193;
LeftTee [0] =   195;
RightTee[0] =   180;
Cross   [0] =   197;

UpperLeft [1] = '\0';
UpperRight[1] = '\0';
LowerLeft [1] = '\0';
LowerRight[1] = '\0';
Vertical  [1] = '\0';
Horizontal[1] = '\0';

UpperTee  [1] = '\0';
LowerTee  [1] = '\0';
LeftTee   [1] = '\0';
RightTee  [1] = '\0';
Cross     [1] = '\0';

// CORNERS
_settextposition(Row,Col);
_outtext(UpperLeft);
_settextposition(Row,Col+(3+1)*SizeX);
_outtext(UpperRight);
_settextposition(Row+(1+1)*SizeY,Col);
_outtext(LowerLeft);
_settextposition(Row+(1+1)*SizeY,Col+(3+1)*SizeX);
_outtext(LowerRight);

// Horizontal Lines

for ( q = 0; q < SizeY + 1 ; q++)
{

for ( k = 0; k < SizeX ; k++)
{

for ( m = 0; m < 3 ; m++)
{

_settextposition(Row+(1+1)*q,(Col+1)+(3+1)*k+m);
_outtext(Horizontal);
}

}
}

// Vertical  Lines

for ( q = 0; q < SizeX + 1 ; q++)
{

for ( k = 0; k < SizeY ; k++)
{

for ( m = 0; m < 1 ; m++)
{
_settextposition((Row+1)+(1+1)*k+m,Col+(3+1)*q);
_outtext(Vertical);
}
}

}
// Upper & LowerTee's

for ( k = 0; k < SizeX - 1 ; k++)
{
_settextposition(Row,Col+(3+1)*k+3+1);
_outtext(UpperTee);

_settextposition(Row+(1+1)*SizeY,Col+(3+1)*k+3+1);
_outtext(LowerTee);
}

// Right & Left Tee's

for ( k = 0; k < SizeY - 1 ; k++)
{
_settextposition(Row+(1+1)*k+1+1,Col);
_outtext(LeftTee);

_settextposition(Row+(1+1)*k+1+1,Col+(3+1)*SizeX);
_outtext(RightTee);
}

// Crosses

for ( k = 0; k < SizeY - 1 ; k++)
{

for ( m = 0; m < SizeX - 1 ; m++)
{
_settextposition(Row+(1+1)*k+1+1,Col+(3+1)*m+3+1);
_outtext(Cross);
}
}

}```

2. When I was doing this, I used an offset called lmargin which was the same, regardless of the size of the box - say 10 char's in from the left side of the monitor.

So the correct column was always lmargin+(sqr number * width of the sqr) + (width of the sqr/2). First sqr is square number 0.

lmargin = obviously needed and a constant regardless of the size of the box or the size of the squares
sqr number * width of the sqr = moves the cursor over to the right sqr's leftmost position
width of the sqr/2 = centers the cursor in the center of the sqr.

You always use an odd width for your sqr size - 5 works well for a display that needs three chars (like an asii chess board). 3 works well for a display of a single digit (like a Sudoku game board display).