another two-dimensional array question

This is a discussion on another two-dimensional array question within the C++ Programming forums, part of the General Programming Boards category; This is a minesweeper game program with the goal of finding 5 bombs by making coordinate guesses: Here's my main ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    another two-dimensional array question

    This is a minesweeper game program with the goal of finding 5 bombs by making coordinate guesses: Here's my main function so far. My question is, why do I get an "Undefined symbol 'minefield' " error? (there's about 5 of these errors since there's 5 void functions that have the same parameters) Is this a problem that could be caused by something outside the main function?

    Code:
    void main()
    {
    
    int row, 
         col,
         r1, 
         c1;
    int num_found=0, 
         num_attempts=0;
         bombs_left=5,
    
    bool all_found=false;
    
    char minefield[10][10];
    
    
    
    
    void reset_array(minefield, row, col);
    
    void print_array(minefield, row, col);
    
    void fill_array_with_bombs(minefield, row, col);
    
    
    system("CLS");
    
    
    void print_array_without_bombs(minefield, row, col);
    
    
    cout<<"Time to start sweeping for mines!";
    
    
    while (row>0 && col>0 && all_found==false)
    {
            cout<<"Please enter a row and column number: ";
            cin>>r1
            cin>> c1;
    
            bool check_for_hit();
    
    
            if (check_for_hit()==true)
            {
                    num_found++;
                    cout<<"There are now "<<bombs_left--<<"bombs left in the minefield";
                    if (bombs_left==0)
                    {
                            all_found=true;
                    }
            }
            num_attempts++;
    
            
            void print_array_without_bombs(minefield, row, col);
    
           
            if (all_found==true)
            {
                    cout<<"It took you "<<num_attempts<<" guesses to find all 5 bombs!  HAHA!";
            }
            else
            {
                    cout<<"You quit the program early.";
            }
    
            
            void print_array(minefield, row, col);
    
    }
    
    }
    Last edited by Troll; 12-10-2005 at 03:26 PM. Reason: grammar correction

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Don't use void main().

    How are you passing your 2D arrays?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Wait! All your prototypes are wrong:
    Code:
    void print_array_without_bombs(minefield, row, col);
    You need a type, as in
    Code:
    void print_array_without_bombs(char (*minefield)[10], int row, int col);
    or
    Code:
    void print_array_without_bombs(char (*)[10], int, int);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    16
    Thank you! I'll most likely have other questions later tongiht.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Code:
    void reset_array(minefield, row, col);
    You might prefer the more intuitive:

    Code:
    void reset_array(minefield[][10], int row, int col)
    Note: the left most dimension is not part of the type of an array.

    In addition, you don't want to put your function declarations inside main(). Move them outside and above main().

    Code:
    int row, 
        col,
         r1, 
         c1;
    Always initialize your variables, including arrays:
    Code:
    char minefield[10][10] = {0};
    Last edited by 7stud; 12-10-2005 at 06:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embaracing Array question
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 04-06-2009, 10:29 AM
  2. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  3. two dimensional string array question
    By Hoser83 in forum C Programming
    Replies: 8
    Last Post: 02-07-2006, 07:15 PM
  4. Array of Structs question
    By WaterNut in forum C++ Programming
    Replies: 10
    Last Post: 07-02-2004, 02:58 PM
  5. Create Array size Question
    By popohoma in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 02:04 AM

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