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 seekRoad(char [][6], int, int);
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";
seekRoad(maze, x, y);
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";
seekRoad(maze, x, y);
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";
seekRoad(maze, x, y);
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";
seekRoad(maze, x, y);
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;
}