stuck on display method

This is a discussion on stuck on display method within the C++ Programming forums, part of the General Programming Boards category; Im doing an advanced extra credit project for my C++ class and am trying to make a Sudoku game based ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    44

    stuck on display method

    Im doing an advanced extra credit project for my C++ class and am trying to make a Sudoku game based on function specifications laid out by the teacher. The problem is that my Display() method is not printing anything out. The idea is that I have a function that feeds a 2 dimensional array of 9x9 that holds SudCell objects into a 4 dimensional array of 3x3by3x3 that holds pointers to SudCell objects. And then I print out a 3x3 section of this array using a SectorDisplay().

    Here is the complete code listing if you would like to run the program:
    http://codepad.org/t72PRLDL

    All the code Im listing here is from the same class except the ToString() method which is called inside the SectorDisplay() method and comes from the SudCell class that makes SudCell objects which is what the arrays hold.

    Here is the Display method:
    Code:
    void Sudoku::SectorDisplay(int sec_row, int sec_col)
    {
       int out = 0, stop = 0;
       for (int x=0;x<3;x++)
          for (int y=0;y<3;y++)
          {
             sector[sec_row][sec_col][x][y]->ToString();
             out++;
             if (out > 2)
             {
                cout << endl;
                out = 0;
                stop++;
                if (stop > 1)
                   stop = 0;
             }
          }
    }
    Here is the ToString() method called from the SudCell class
    Code:
    string SudCell::ToString()
    {
       string output;
       int boolcount = 0;
       int whichdigit = 0;
       for (int x=0;x<9;x++)
       {
          if (digits[x] == true)
          {
             whichdigit = x;
             boolcount++;
          }
       }
       if (boolcount > 1 || boolcount < 1)
          output = " - ";
       else
       {
          whichdigit++;
          ostringstream cnvrt;
          cnvrt << whichdigit;
          output = cnvrt.str();
          output = " " + output + " ";
       }
    
       return output;
    }
    Here are what the two arrays look like:
    Code:
    SudCell* sector[SQRT_NUM_VALS][SQRT_NUM_VALS]  [SQRT_NUM_VALS][SQRT_NUM_VALS];
    SudCell suds[NUM_VALS][NUM_VALS];
    Here is the WireUpSectorArrays() method which feeds pointers of the suds array into the sector array:
    Code:
    void Sudoku::WireUpSectorArrays()
    {
       int inc3 = 0, inc3acr = 0, inc3down = 0, inc3downjump = 0;
       for(int x=0;x<MAX_VAL;x++)
          for(int y=0;y<MAX_VAL;y++)
          {
             sector[inc3downjump][inc3acr][inc3down][inc3] = &suds[x][y];
             //cout << sector[inc3downjump][inc3acr][inc3down][inc3]->SudCell::ToString();
             inc3++;
             if(inc3 > 2)
             {
                inc3 = 0;
                inc3acr++;
                if (inc3acr > 2)
                {
                   inc3acr = 0;
                   inc3down ++;
                   if(inc3down > 2)
                   {
                      inc3down = 0;
                      inc3downjump++;
                      if(inc3downjump > 2)
                         inc3downjump = 0;
                   }
                }
             }
          }
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Go to your display function; search for "cout". Notice that the only line that contains cout is "cout << endl" and conclude that the only thing you're printing is blank lines. Then, find the things you want to print and actually print them.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    44
    tabstop- big thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Figure out how method was called?
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 02-07-2009, 09:43 AM
  2. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  3. Static templated method problem
    By mikahell in forum C++ Programming
    Replies: 6
    Last Post: 11-19-2006, 08:19 AM
  4. about scan 7-segment display via parallel port
    By mobdawg in forum C Programming
    Replies: 4
    Last Post: 09-11-2002, 06:11 AM
  5. Replies: 3
    Last Post: 12-03-2001, 12:45 PM

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