I need help with my code, What is wrong with it? It is supposed to print the maze every time the function is called. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I need help with my code, What is wrong with it? It is supposed to print the maze every time the function is called.

#include <iostream> using namespace std; const int ROWMAX = 4; const int COLMAX = 3; char maze[ROWMAX][COLMAX] = { { " " }, { " + +-+ " }, { " | | " }, { " +-+ + " }, { " | | " }, { " +-+-+ " }, { " | | " }, { " +-+ + " }, { " " }, }; void printMaze(); void runMaze(int, int); void runMaze(int row, int col) for(int row = 0; row < ROWMAX; row++) { for(int col=0; col < COLMAX; col++) cout << maze[row][col]; cout << "\n"; } void runMaze(int row, int col) { if( (row>0 && row<ROWMAX) && (col>0 && col<COLMAX)) { if( maze[row][col] == 'W' ) return; if( maze[row][col] == ' ') { maze[row][col]='*'; runMaze(row, col+1); runMaze(row, col-1); runMaze(row-1, col); runMaze(row+1, col); } } } int main() { cout << "Automatic Maze Solver" << endl; printMaze(); cout << "START" << endl; runMaze(1, 2); printMaze(); return 0; }

29th Sep 2016, 4:08 AM
Raul
Raul - avatar
1 Answer
+ 2
I don't know fully.. 1.there are two functions with same return type, name, same number and type.of arguments...(they are not overloaded) 2.In second Runmaze function the return statement is incomplete.. void functions are not necessary to return anything.. 3.there is no need for function declaration if the function is defined above main program
29th Sep 2016, 5:45 AM
Balaji Rs
Balaji Rs - avatar