Thread: debug...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    debug...

    can't figure out what's wrong with this program...
    it's minesweeper program..
    input of (0, 0) is automatic win...
    if I uncover some area that doesn't have mines, it opens all area.
    can't figure out what's wrong..


    PHP Code:
    int calculate(int iint j)
    {

    int sum 0;


        
    /* Calculate values of cells surounding mines */
           
    if (mines[i][j] != '*')
          {
          if(
    mines[i+1][j] == '*')
               {
               
    sum calculate(ij);
                }
          else if(
    mines[i+1][j+1] == '*')
                {
                   
    sum calculate(ij);
                 }
               else if(
    mines[i+1][j] == '*')
                    {
                        
    sum calculate(ij);
                     }
                     else if(
    mines[i+1][j-1] == '*')
                          {
                            
    sum calculate(ij);
                          }
                          else if(
    mines[i][j-1] == '*')
                               {
                               
    sum calculate(ij);
                                }
                               else if(
    mines[i-1][j-1] == '*')
                                    {
                                    
    sum calculate(ij);
                                    }
                                    else if(
    mines[i-1][j] == '*')
                                        {
                                        
    sum calculate(ij);
                                        }
                                        else
                                          {
                                             
    sum calculate(ij);
                                          }
               }

          return 
    sum;

    Last edited by jk81; 10-24-2002 at 09:13 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Please don't post hundreds of lines of code at a time. Attach a file if you insist on showing the entire program. This is one problem I spotted before I got tired of reading and quit:
    Code:
     for( x = 0; x < 9; x++ )
    
            for( y = 0; y < 9; y++ )
    
                mines[x][y] = '0';
    You declare mines as a 10 x 10 array. Here however, you only initialize 9 x 9. This is not what you want. Try this:

    for( x = 0; x < 10; x++ )

    Remember, arrays go from 0 to size-1. Thus, valid array cells are 0 to 9. If you stop before 9, then your nineth column and nineth row never get filled.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    32
    i reduced the code above..
    sorry about that..
    i narrowed down to those two functions..

    I found another problem: calculating portion does not work..
    Last edited by jk81; 10-24-2002 at 09:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 02:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM