I am trying to make a maze program. It is suppose to display the maze before it is solved, then solved. After that is should be able to random generate a different maze that needs to be solved. My problem is that when I compile I get this, Any suggestions would be great. Thank you. :
try.cpp: In function âvoid findpath(int (*)[50], int, int, int, int)â:
try.cpp:92: error: return-statement with a value, in function returning 'void'
try.cpp:97: error: return-statement with a value, in function returning 'void'
try.cpp:102: error: return-statement with a value, in function returning 'void'
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define N 50 //Defines the column to be able to use
#define M 50 //Defines the rows to be able to use
#define PATH 0 //Path will start at 0
#define BLOCK 1
#define TRUE 1
#define FALSE 0
void createmaze(int maze[N][M]); // this creates the maze with walls and holes for the start and finish
void printmaze(int maze[N][M],int ht,int wt); // this prints out the initial maze
void findpath(int maze[N][M],int high,int wid, int x, int y); // this finds the path from start to finish
int wall(int maze[N][M], int x, int y); // this finds if there is a wall north,south,east,west
int main()
{
srand((unsigned)time(NULL));
int maze[N][M];
int width, height;
cout<<"How big do you want the height"<<endl;
cin>>height;
cout<<"How big do you want the width"<<endl;
cin>>width;
cout<<"This is the maze first look:"<<endl;
createmaze(maze);
printmaze(maze,height,width);
cout<<"This is maze with the path found"<<endl;
findpath(maze,height,width,1,1);
printmaze(maze,height,width);
return 0;
}
int wall(int maze[N][M],int x, int y)
{
if(maze[x - 1][y] == BLOCK
&& maze[x][y - 1] == BLOCK
&& maze[x][y + 1] == BLOCK
&& maze[x + 1][y] == BLOCK)
{
return 1;
}else {
return 0;
}
}
void createmaze(int maze[N][M])
{ for(int a = 0; a < N; a++)
{
for(int b = 0; b < M; b++)
{
if(a % 2 == 0 || b % 2 == 0)
maze[a][b] = 1;
else
maze[a][b] = PATH;
}
}
}
void printmaze(int maze[N][M], int ht, int wt)
{
cout<<" MAZE: ";
for(int c =0; c< ht; c++)
{ for(int d; d < wt; d++)
{ if( maze[c][d] == BLOCK)
{ cout<< "+";
}else
{ cout<< " ";
}
}
cout<<"\n";
}
}
void findpath(int maze[N][M], int high, int wid,int x, int y)
{
// If x,y is outside maze, return false.
if ( x < 0 || x > high- 1 || y < 0 || y > wid - 1 )
{ return FALSE;
}
// If x,y is the goal, return true.
if ( maze[x][y] == 'G')
{
return TRUE;
}
// If x,y is not open, return false.
if ( maze[x][y] != '.' && maze[x][y] != 'S' )
{ return FALSE;
maze[x][y] = '+'; // Mark x,y part of solution path.
}
// If find_path North of x,y is true, return true.
if ( findpath(x, y - 1) == 1 )
{ return TRUE;
}
// If find_path East of x,y is true, return true.
if ( findpath(x + 1, y) == 1 )
{ return TRUE;
}
// If find_path South of x,y is true, return true.
if ( findpath(x, y + 1) == 1 )
{ return TRUE;
}
// If find_path West of x,y is true, return true.
if ( findpath(x - 1, y) == 1)
{ return TRUE;
maze[x][y] = 'x'; //mark the repeat steps
}
return FALSE;
}