MAZE Problem

This is a discussion on MAZE Problem within the C++ Programming forums, part of the General Programming Boards category; I am confused...XX..... But how can i add element into this??? like above?? ..... sorry...

  1. #46
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    I am confused...XX.....

    But how can i add element into this???
    like above??


    ..... sorry

  2. #47
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    i think i figure out now hahah
    thx thx

  3. #48
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by peacealida View Post
    I am confused...XX.....

    But how can i add element into this???
    like above??


    ..... sorry
    I have an example posted already. You have one array -- it has three dimensions. If you're going to initialize it, you have to do it now, when you declare it, and you need to initialize it all (or at least everything you plan to do). So do so. We're going to do the random one later, but we need all 0's so:
    Code:
    {
    {{0}},
    Then you need the first array; copy and paste the whole thing in from
    Code:
    {{ lots of numbers up to}}
    }
    . And there you are.

  4. #49
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    Code:
    int matrix[MATRIX_SIZE][MATRIX_SIZE];
    int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; ={ {{0}}, 
    
    { {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
        {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
        {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
        {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
        {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0},
        {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0},
        {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0},
        {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
        {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
        {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
      };}
    
    return matrix_data[0];
    int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];
    these should make sense?


    What i need to write in the int main() ?

    i think i need to allow the user input and read the data from the array and output.

    I am trying to produce the code, but it comes more than 15 errors.

    Wt else do u need to modify????






    -----------THX---THX-------------

  5. #50
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    Code:
    int main()
    {
        cout <<"Ender Maze wanted, 0,1,2,3:\n";
        cout <<"    0- Random Maze\n";
        cout <<"    1- Set Maze (1)\n";
        cout <<"    2- Exit\n";
        cin >> x;
        
        return 0;
    I have put these into the int main() What else is missing? Or i need to define other function??
    plz help

    cheers

  6. #51
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by peacealida View Post
    Code:
    int main()
    {
        cout <<"Ender Maze wanted, 0,1,2,3:\n";
        cout <<"    0- Random Maze\n";
        cout <<"    1- Set Maze (1)\n";
        cout <<"    2- Exit\n";
        cin >> x;
        
        return 0;
    I have put these into the int main() What else is missing? Or i need to define other function??
    plz help

    cheers
    Who knows what's missing? This doesn't do anything apart from: printing a menu, and getting a choice back. Everything else you want done, you have to do.

  7. #52
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    OIC
    This is what i though coz they dun read the input and get the output.
    so i need to create a function for the data to process!?

    So i need specific 0 is to choose the map [0]
    and 1 i choose map[1]??

    for(int maze=0; maze<3 ; maze++)
    cout<<matrix_size[maze]<<"------"<<matrix_data[n]<<endl;
    these should put inside the int main() or void()??


    I am really sorry for all these......

  8. #53
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can do it inside main directly, or put it another function, as you wish; but if you put it in another function you do have to call that function from main, or else it won't happen. Notice that there is no function called void().

  9. #54
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    Sorry
    So i think i will put them inside the main...

    I have seen the other tread you reply
    using printf and scanf

    are they more useful for me?? (I know it sounds weired)

    I will use that method to see does it get me anywhere.Thanks

    I am sorry for all these question, but i really trying to get them work, I have not stopping on these since you repled me this morning ahahaha.

    ---------Thanks God------------

  10. #55
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    I have done the following changes in the int main()

    Code:
    int main()
    using namespace std;
    {
        
        int maze;
        
        cout <<"Enter Maze wanted, 0,1,2,3:\n";
        cout <<"    0- Random Maze\n";
        cout <<"    1- Set Maze (1)\n";
        cout <<"    2- Exit\n";
        
        cin >> maze;
        {
        for (maze =0; maze < matrix_data[n]; maze++)
            cout<<matrix_data[n] <<endl;
        
    }
    still 3 errors, any 1 can point out wt's going on????
    Thanks Thanks

  11. #56
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The three errors tell you exactly what's going on:
    unclosed brace on line "{" (right after cin >> maze)
    variable n not defined
    unable to compare int (maze) with int[][] (matrix_data[n]) (although your error might say something about conversions from int[][] to int)

    Not a compile error, probably, but cout << matrix_data[n] will probably print out a hex memory address, since matrix_data[n] decays into a pointer.

  12. #57
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    Still getting syntax error

    Code:
    int main()
    using namespace std;
    {
        int maze[][], n;
        
        cout <<"    Enter Maze wanted, 0,1,2:\n";
        cout <<"    0- Random Maze\n";
        cout <<"    1- Set Maze (1)\n";
        cout <<"    2- Exit\n";
        
        cin >> maze[][];
        matrix_data[n] =maze[][];
        {
        for (maze[][] =0; maze[][] < matrix_data[n]; maze[][]++)
        cout<<matrix_data[n] <<endl;
        printf("%d\n", matrix_data[n]);
        return 0;
    }
    }

    i am also having error on this line....
    Code:
    int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; ={ {{0}},
    { {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
        {0,

    also wt this mean?


    "unable to compare int (maze) with int[][] (matrix_data[n]) "

  13. #58
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by peacealida View Post
    Still getting syntax error

    Code:
    int main()
    using namespace std;
    {
        int maze[][], n;
        
        cout <<"    Enter Maze wanted, 0,1,2:\n";
        cout <<"    0- Random Maze\n";
        cout <<"    1- Set Maze (1)\n";
        cout <<"    2- Exit\n";
        
        cin >> maze[][];
        matrix_data[n] =maze[][];
        {
        for (maze[][] =0; maze[][] < matrix_data[n]; maze[][]++)
        cout<<matrix_data[n] <<endl;
        printf("%d\n", matrix_data[n]);
        return 0;
    }
    }

    i am also having error on this line....
    Code:
    int matrix_data[2][MATRIX_SIZE][MATRIX_SIZE]; ={ {{0}},
    { {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
        {0,

    also wt this mean?


    "unable to compare int (maze) with int[][] (matrix_data[n]) "
    Does the initializer continue after the 0, ? You can't just stop.

    And the last means what it says: you can't compare (using < for less than) an integer to a matrix. What would that mean?

  14. #59
    Registered User
    Join Date
    Mar 2008
    Posts
    85
    Code:
                  .
                  .
                  .
                  .
    ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0},
        {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
        {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
        {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}
      };}
    
    return matrix_data[0];
    int trace_matrix[MATRIX_SIZE][MATRIX_SIZE];
    
    void output_program(struct prog *progp)
    {
      char *codep = progp->code;
      int token;
        
        while (token = *codep++)
         fputs(token_table[token].name, stdout);
      putchar('\n');
    }
    
    
    void print_matrix(void)
    {  int i, j; char symbs[] = " OX";
    
       for (i=0; i < MATRIX_SIZE; i++)
       {  for (j=0; j < MATRIX_SIZE; j++)
              putchar(symbs[trace_matrix[i][j]]);
          putchar('\n');
       }
    }
    This is the end of it....



    Code:
    for (maze[][] =0; maze[][] << matrix_data[n]; maze[][]++)
    So aboe must be wring...

    If i can't use integer to a matrix,,,, so how can i retrieve the data?

    Thanks Thanks

  15. #60
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Notice in your initializer that you've embedded the semicolon in the thing, rather than being at the end like it should.

    Code:
    for (maze[][] =0; maze[][] << matrix_data[n]; maze[][]++)
    This is so amazingly wrong that it makes me give up hope.

    matrix_data is a 3-dimensional array.
    matrix_data[0] is a 2-dimensional array (namely, a map).
    matrix_data[0][1] is a 1-dimensional array (specifically, the second row of the map).
    matrix_data[0][1][2] is an integer (the third number in the second row of the map).

    You can only deal with specific elements of the array.

Page 4 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  2. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 12:52 AM
  3. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

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