Thread: Trouble with for loop to create 5x4 grid box

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

    Trouble with for loop to create 5x4 grid box

    So I just started c just like 3 months ago so bare with me.This assignment is due tomorrow and my grade depends on this so I really could use some help!

    My professor wants us to create a grid box; however, the values of the grid box are not fixed so he will be changing the values of the variables manually so no matter what value my professor puts in it should still remain the shape of a grid box. The corners of the grid box work fine so if you change the values in the calling program they will work. The problem I am having though is creating the loops for the horizontal. As you can see I have attemped to try to create the horizontal lines for the grid box but somehow I just can't seem to get it!Trouble with for loop to create 5x4 grid box-box-png (The position for this grid box starts at row 5 column 3. The variables 5(row),6(column),4(rows down),5(columns to the right),6(width),3(height),12(text color)
    // Calling Program
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #include "Myhead.h"
    #include "GridBox.h"
    
    int main()
    {
      // Heading();
        ClearTheScreen();
    
        GridBox(5,6,4,5,6,3,12); //Professor will change these values                            
    
        PauseTheScreen();
    }
    Code:
    // Source Code
    void GridBox(int Row,int Col, int RowDwn,int ColRght,int Width,int Height,int Color)
    {
        int k,m,q,i;
    
        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];
    
        UpperTee[0] = 194;
        LowerTee[0] = 193;
        LeftTee [0] = 195;
        RightTee[0] = 180;
        Cross   [0] = 197;
    
        UpperTee [1] =   '\0';
        LowerTee [1] =    '\0';
        LeftTee    [1] =   '\0';
        RightTee   [1]  =   '\0';
        Cross        [1] =    '\0';
    
        _settextcolor(14);
    
    
        UpperLeft [0] = 218;
        UpperRight[0] = 191;
        LowerLeft [0] = 192;
        LowerRight[0] = 217;
        Vertical  [0] = 179;
        Horizontal[0] = 196;
    
    
    
        UpperLeft [1] = '\0';
        UpperRight[1] = '\0';
        LowerLeft [1] = '\0';
        LowerRight[1] = '\0';
        Vertical  [1] = '\0';
        Horizontal[1] = '\0';
    
        // CORNERS
        _settextposition(Row,Col);
        _outtext(UpperLeft);
        _settextposition(Row,Col+Row+RowDwn+ColRght+Width+Height+Color);
        _outtext(UpperRight);
        _settextposition(Row+Color+Height,Col);
        _outtext(LowerLeft);
        _settextposition(Row+Color+Height,Col+Row+RowDwn+ColRght+Width+Height+Color);
        _outtext(LowerRight);
    
        // draw the Horizontals
        for ( q = 0; q < Row ; q++)
        {
           for ( k = 0; k < ColRght; k++)
           {
              for ( m = 0; m < Width ; m++)
              {
                _settextposition(Row,Width+ColRght*k+m); //top horizontal
                _outtext(Horizontal);
    
                _settextposition(Row+RowDwn*q,Width+ColRght*k+m); //bottom horizontal
                _outtext(Horizontal);
    
    
               
               }
    
              
           }
        }
    }
    Last edited by hungrymouth; 11-28-2012 at 02:15 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You could initialise your strings like so.
    Code:
    char *UpperTee = "\xC2";
    It seems that you're just "off" moving the rows into the correct position.
    Perhaps do something like
    Code:
    for ( q = Row; q < Row + RowDwn; q++)
    So any positioning for row is just 'q' rather than anything more complicated.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble with the tic tac toe grid
    By shruthi in forum C Programming
    Replies: 2
    Last Post: 02-01-2012, 02:01 AM
  2. Trying to create a loop that creates csv files
    By airesore in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2011, 06:32 PM
  3. Please help create a loop for embedded SQL
    By cjohnman in forum C Programming
    Replies: 4
    Last Post: 04-24-2008, 06:46 AM
  4. how will i create a loop?
    By nesir in forum C Programming
    Replies: 15
    Last Post: 07-19-2006, 10:43 AM
  5. create menu with do while loop advice pls
    By ali_1 in forum C++ Programming
    Replies: 1
    Last Post: 04-23-2006, 09:34 PM

Tags for this Thread