# Thread: i need some help ><

1. ## 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 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;
}```

2. 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. Code:
`int seekRoad(char [4][6], int, int);`
You can't make an array parameter. How would you pass data to it?

4. 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";
}```

5. 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. 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
}```

7. 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. 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

what does this mean?

10. 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. ok so in order to get ride of that problem
i have to
1) find a function that fits that description for it?
or?
is there another way i get get around it?

12. What do you mean that you have to find one ?
You declared it, you called it so you have to implement it as well.
Kurt

13. ok i got into gear
and got some stuff down
and this is what i have
Code:
```#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
char maze[4][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";
cout << maze[0][0] << endl;

int result = seekRoad(maze, 0, 0);
if (result == -1){
cout << "No exit!\n";}
else if (result == 1)
cout << "Good\n";
else
cout << "Error\n";
system("PAUSE");

return 0;
}
int seekRoad(char maze[][6], int x, int y)
{  {if( (x<=4 && y<=6 ));}
if (maze[x][y]=='E')
return -1;
else if (maze[x][y+1]=='R'){
maze[x][y]='o';
y++;
cout << "current X = " << x << endl;
cout << "current Y = " << y <<endl;
cout << maze[x][y]<< endl;
cout << maze[x][y-1] <<endl;
return 1;}
else
return 2;
}```
another problem occured
when i script above, it works (only one cell though but none the less its still better than the prototype) but when i include
Code:
``` else if (maze [x][y-1] == 'R');
else if (maze [x+1][y] == 'R');
else if (maze [x-1][y] == 'R')```
to the end of
Code:
` else if (maze[x][y+1]=='R'){`
and run the file, it produces an error and i dont understand why
can anyone help me?

14. When you use some index - you should be sure - that it inside the bounds.

When you retreive the value on index x-1 - make sure it is >=0 and < maxwidth

If you found an empty space to the left - shouldn't you move there?

Seeing your code you do nothing in the other 3 cases except the implemented one...

15. ok so i finished the work
but then even if the maze doesnt work i still get the comment "good"
what went wrong ><
Code:
```#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
char maze[4][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";
cout << maze[0][0] << endl;

int result = seekRoad(maze, 0, 0);
if (result == -1){
cout << "No exit!\n";}
else if (result == 1)
cout << "Good\n";
else
cout << "Error\n";
system("PAUSE");

return 0;

}
int seekRoad(char maze[][6], int x, int y)
{
if (maze[x][y]=='E')
return -1;
else if (maze[x][y+1]=='R'){
maze[x][y]='o';
y++;
cout << "current X = " << x << endl;
cout << "current Y = " << y << "\n\n";
return 1;}
else if (maze[x+1][y]=='R'){
maze[x][y]='o';
x++;
cout << "current X = " << x << endl;
cout << "current Y = " << y << "\n\n";
return 1;}
else if (maze[x][y-1]=='R'){
maze[x][y]='o';
y--;
cout << "current X = " << x << endl;
cout << "current Y = " << y << "\n\n";
return 1;}
else if (maze[x-1][y]=='R'){
maze[x][y]='o';
x--;
cout << "current X = " << x << endl;
cout << "current Y = " << y << "\n\n";
return 1;}
else if (maze[x][y+1]=='E'){
maze[x][y]='o';
y++;
cout << "Exit X = " << x << endl;
cout << "Exit Y = " << y << "\n\n";
return 1;}
else if (maze[x+1][y]=='E'){
maze[x][y]='o';
x++;
cout << "Exit X = " << x << endl;
cout << "Exit Y = " << y << "\n\n";
return 1;}
else if (maze[x][y-1]=='E'){
maze[x][y]='o';
y--;
cout << "Exit X = " << x << endl;
cout << "Exit Y = " << y << "\n\n";
return 1;}
else if (maze[x-1][y]=='E'){
maze[x][y]='o';
x--;
cout << "Exit X = " << x << endl;
cout << "Exit Y = " << y << "\n\n";
return 1;}

else
return 2;
}```