Numbers inside grid box help

This is a discussion on Numbers inside grid box help within the C Programming forums, part of the General Programming Boards category; Ok so my professor wants us to produce binary numbers in the grid box that I just made. I am ...

  1. #1
    Registered User hungrymouth's Avatar
    Join Date
    Oct 2012
    Posts
    19

    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);          
              }
           }
    
    }
    Attached Images Attached Images  
    Last edited by hungrymouth; 12-03-2012 at 03:00 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-13-2010, 03:14 PM
  2. 2d grid
    By lord in forum C++ Programming
    Replies: 4
    Last Post: 02-03-2009, 07:06 PM
  3. Searching through a grid of numbers
    By drag0n69 in forum C Programming
    Replies: 2
    Last Post: 03-18-2008, 12:52 PM
  4. hex grid
    By waterst in forum C Programming
    Replies: 2
    Last Post: 10-30-2002, 02:36 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21