Thread: i need some help ><

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    8

    i need some help ><

    hi everybody i'm new to this msg board
    currently i'm working on a task which involves mazing
    i have learnt C++ for a month and must say i am not very good at it
    well while i was coding, my friend took a look at my codes and told me i have a major mistake and ever since then i've been staring at the script and cant figure it out
    can someone help me out here? by the way this is not complete
    Code:
    #include <iostream.h>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int seekRoad(char [4][6], int, int);
    
    int main() 
    {
             
        char maze[][6] = {{'S', 'R', 'X', 'X', 'X', 'X'},
                           {'X', 'R', 'X', 'X', 'R', 'E'},
                           {'X', 'R', 'R', 'X', 'R', 'X'},
                           {'X', 'X', 'R', 'R', 'R', 'X'}};
    
    
        cout << "Start X = 0\n";
        cout << "Start Y = 0\n\n";
    
        int result = seekRoad(maze, 0, 0);
        if (result == -1) {
          cout << "No exit!\n";
        if (maze [x][y+1] =="R" );  
      else if (maze [x][y-1] == "R");
      else if (maze [x+1][y] == "R");
      else if (maze [x-1][y] == "R");
        }
    
        return 0;
    }
    Last edited by kid1412; 10-26-2006 at 10:05 AM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    else if (maze [x][y-1] == "R");
      else if (maze [x+1][y] == "R");
      else if (maze [x-1][y] == "R");
    One thing, maze is an array of chars, so you should be comparing maze[x][y] with character 'R'.

    Another thing is, you'll go out of bounds here. For example x-1 could easily be -1.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    int seekRoad(char [4][6], int, int);
    You can't make an array parameter. How would you pass data to it?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Quote Originally Posted by maxorator
    Code:
    int seekRoad(char [4][6], int, int);
    You can't make an array parameter. How would you pass data to it?
    Considering that is the prototype, it's perfectly fine. I believe it's also valid to leave arguments unnamed if they aren't referenced inside the function, e.g.:
    Code:
    void foo(int)
    {
      std::cout<<"Foo";
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    8
    Quote Originally Posted by maxorator
    Code:
    int seekRoad(char [4][6], int, int);
    You can't make an array parameter. How would you pass data to it?
    i'm sorry but what do you mean by that
    so what am i supposed to do to fix it?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    if (maze [x][y+1] =="R" );
    else if (maze [x][y-1] == "R");
    else if (maze [x+1][y] == "R");
    else if (maze [x-1][y] == "R");

    You need to put these lines (with some of the changes already mentioned) in a new function called seekRoad.

    Maybe
    Code:
    int seekRoad(char maze[4][6], int x, int y) {
      // more here
        if (maze [x][y+1] =="R" );  
      else if (maze [x][y-1] == "R");
      else if (maze [x+1][y] == "R");
      else if (maze [x-1][y] == "R");
      // more here
    }
    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.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    8
    ok i worked and played a bit with it and after reading the comments i did a lil alteration on my codings
    but now i have another problem
    Code:
    #include <iostream>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int y = 1;
    int x = 2;
    
    int seekRoad(char [][6], int x, int y);
    
    int main() 
    {
    
             
        char maze[][6] = {{'S', 'R', 'X', 'X', 'X', 'X'},
                           {'X', 'R', 'X', 'X', 'R', 'E'},
                           {'X', 'R', 'R', 'X', 'R', 'X'},
                           {'X', 'X', 'R', 'R', 'R', 'X'}};
    
    
        cout << "Start X = 0\n";
        cout << "Start Y = 0\n\n";
    void runMaze(int, int);
    
        int result = seekRoad(maze, 0, 0);
        if (result == -1) {
          cout << "No exit!\n";
    
        }
        {if( (x<=4 && y<=6 )) {
    {if( maze[x][y] == 'E' ) return 0;
        {if (maze [x][y+1] =="R" )return 0;  
      else if (maze [x][y-1] == "R")return 0;
      else if (maze [x+1][y] == "R")return 0;
      else if (maze [x-1][y] == "R")return 0;
        return 0;}}}
    }}
    i keep getting a ISO C++ forbids comparision between pointer and interger

    what does that mean and how do i get rid of it? D:

  8. #8
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if (maze [x][y+1] =="R" )return 0;  
      else if (maze [x][y-1] == "R")return 0;
      else if (maze [x+1][y] == "R")return 0;
      else if (maze [x-1][y] == "R")return 0;
    "R" is a pointer to an array of char.
    all the "R" should be 'R'
    Kurt

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    8
    [Linker error] undefined reference to `seekRoad(char (*) [6], int, int)'

    what does this mean?

  10. #10
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I'd say it means that there is no function implemented that is called seekRoad, returns an int and takes an array of array of characters of length 6 and two ints as parameters.
    BTW:
    declaring
    Code:
    void runMaze(int, int);
    inside of main() looks quite useless to me.

    Kurt

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You should not ignore the return value of your function

    I mean like this

    Code:
    seekRoad(maze, x, y);
             return 1;
    You always return 1 independently of the return value of the seekRoad

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. primitive question ><
    By MicroFiend in forum Game Programming
    Replies: 5
    Last Post: 10-14-2005, 10:14 AM
  2. STEP turbo C 3.0 >< Borland 5.02
    By Huh..... in forum C Programming
    Replies: 0
    Last Post: 03-12-2002, 07:54 AM
  3. searching ><
    By hyaline in forum C Programming
    Replies: 1
    Last Post: 09-16-2001, 05:29 AM