Hi whenever I compile my program, I am getting this as a a error.

well.cpp: In function âvoid printmaze(CELL (*)[20], std::string)â:
well.cpp:234: error: a function-definition is not allowed here before â{â token
well.cpp:416: error: expected `}' at end of input
well.cpp:416: error: expected `}' at end of input
well.cpp:416: error: expected `}' at end of input
well.cpp:416: error: expected `}' at end of input
well.cpp:416: error: expected `}' at end of input

i dont understand why. Here is the code. Thanks for all the help in advance

#include <iostream>
#include <string>
#include <ctime>
#include <cmath>
using namespace std;

#define row 20
#define col 20

struct CELL
{	
	bool start, finish, goal, travel;		//to show if the current room is the beginning
	bool WEST, NORTH, SOUTH, EAST;
	string goback;		//stores the direction it took to get to the current room

	CELL()
	{	/* put all the global variables to false so when it searches
		it knows that it hasn't been there yet */
		start=false;
		finish=false;
		goal=false;
		WEST=true;
		EAST=true;
		NORTH=true;
		SOUTH=true;
		goback="null";
	}

};
void printmaze(CELL arr[][col],string s);
void generatemaze(CELL arr[][col],int crow,int ccol);

int main(int argc, char* argv[])
{
	//sets row and col to 20 as a start.
//	int row;
//	int col;
	string go="NULL";

	//numbers less than 4 are either invalid (negative numbers) or just too small.
	if(row<4)
	{
		cout<<"That's much too small, it's now 20"<<endl;
		
	}
	
	if(col<4)
	{
		cout<<"That's much too small, it's now 20"<<endl;
		
	}
	
	srand((unsigned)time(NULL));   //for randomization
	CELL arr[row][col];


/* this will give the random walls that will be places and taken
	away for the beginning part */

	int randrow; //all three variables are to help randomly pick a row and column to choose beginning point
	int randcol;
	int randj;
	// this is where a random row and col are selected for the beginning of the maze
	randrow=rand()%row;
	if(randrow==0 || randrow==row-1)
		randcol=rand()%col;
	else if(randrow!=0 && randrow!=row-1)
	{
		randj=rand()%2;
		if(randj==0)
		{
			randcol=0;
		}
		else if(randj==1)
		{
			randcol=col-1;
		}
	}
	arr[randrow][randcol].start=true;      //setting the randomly chosen beginning of the maze
					   //and based on its location, opening a wall to the outside
	if(randrow==0)                         
		arr[randrow][randcol].NORTH=false;
	else if(randrow==row-1)
		arr[randrow][randcol].SOUTH=false;
	else if(randcol==0)
		arr[randrow][randcol].WEST=false;
	else if(randcol==col-1)
		arr[randrow][randcol].EAST=false;

	
	int rend=randrow;   //these variables are to randomly pick a row and column for
	int cend=randcol;   //the location of the ending of the maze


	// this is where the random row and col are chosen for the ending of the maze
	while(cend==randrow || cend==randcol)
	{	rend=rand()%row;
		if(rend==0 || rend==row-1)
			cend=rand()%col;
		else if(rend!=0 && rend!=row-1)
		{
			randj=rand()%2;
			if(randj==0)
			{
				cend=0;
			}
			else if(randj==1)
			{
				cend=col-1;
			}
		}
	}
	
	arr[rend][cend].finish=true;    //setting the randomly chosen ending of the maze
											 //and based on its location, opening a wall to the outside
	if(rend==0)                        
		arr[rend][cend].NORTH=false;
	else if(rend==row-1)
		arr[rend][rend].SOUTH=false;
	else if(cend==0)
		arr[rend][cend].WEST=false;
	else if(cend==col-1)
		arr[rend][cend].EAST=false;
	
	/* these are the functions that will generate and print the maze */
	generatemaze(arr, randrow, randcol);            
	printmaze(arr, go);            

return 0;
}

void printmaze(CELL arr[][col], string s)
{
	for(int i=0; i<row; i++)		//start out in the first row
	{
		for(int j=0; j<col; j++)		//start out in the first column, but printing out only the top
		{								//walls of the current row
			if(i==0)
			{
				if(arr[i][j].NORTH)
					cout << "+-";		//prints out the top left corner with wall if wall is turned on
				else
					cout << "+ ";
			}
			else if(i!=0)
			{
				if(arr[i][j].NORTH==true && arr[i-1][j].SOUTH==true)
					cout << "+-";
				else
					cout << "+ ";
			}
			if(j==col-1)		//when the last column is reached, an extra "+" is printed to complete
				cout << "+";	//the corner of the maze
		}

		cout << endl;

		for(int j=0; j<col; j++)		//here the middle part of the current row is printed
		{	if(j==0)		//if current column is 0 then run this code
			{
				if(arr[i][j].WEST)
					cout << "|";		//prints out the left wall until the end of the current row
				else					//then prints the right wall
					cout << " ";

				if(arr[i][j].start)		//if current room is beginning print out B
					cout << "S";
				else if(arr[i][j].finish)		//if current room is end print out E
					cout << "F";		
				else
				{
					if(s=="go")		//if 1 is sent to the function, print out the original maze
					{
						cout << " ";
					}
					
			if(j!=0 && j!=col-1)
			{
				if(arr[i][j].WEST==true && arr[i][j-1].EAST==true)
					cout << "|";
				else 
					cout << " ";

				if(arr[i][j].start)
					cout << "S";
				else if(arr[i][j].finish)
					cout << "F";			
				else
				{	if(s=="go")
					{
						cout << " ";
					}
					
			else if(j==col-1)		//code goes here if i am at the end of the middle part of the 
			{						//room in the current row so it can print the right wall
				if(arr[i][j].WEST==true && arr[i][j-1].EAST==true)
					cout << "|";
				else 
					cout << " ";
				if(arr[i][j].start)
					cout << "S";
				else if(arr[i][j].finish)
					cout << "F";
				else
				{	if(s=="go")
					{
						cout << " ";
					}

				if(arr[i][j].EAST)		//print out the right wall
					cout << "|";
				else
					cout << " ";
			}
		}
		cout << endl;

		if(i==row-1)		//prints out the bottom walls of the current room in the current row
		{
			for(int j=0; j<col; j++)
			{
				if(arr[i][j].SOUTH)
					cout << "+-";
				else
					cout << "+ ";
				if(j==col-1)
					cout << "+";
			}
		cout << endl;
		}		
	}
}
void generatemaze(CELL arr[][col], int crow, int ccol)
{
	int direc=4;		//start out assuming you can go in 4 directions
	int randomdir=-1;		//for picking out a random direction later
	
	bool GONORTH=true;		//assume you can go up
	bool GOSOUTH=true;	//" " down
	bool GOWEST=true;	//" " left
	bool GOEAST=true;	//" " right

	
	int numup=-1;		//for assigning a random number to up
	int numdown=-1;		//" " down
	int numleft=-1;		//" " left
	int numright=-1;	//" " right

	int cnttravel=0;		//for checking how many rooms have been pathed
	int cells=(row*col);		//to know how many rooms the maze has



	for(int i=0; i<row; i++)
	{
		for(int j=0; j<col; j++)
		{
			if(arr[i][j].travel)
			{	cnttravel++;		//for every room that is pathed, numpathed is incremented
			}
		}
	}
	
	if(cnttravel==cells)		//if the number of rooms that are pathed is equal to 
		return;					//the number of rooms then we are finished
	if(arr[crow][ccol].finish)		//if we have reached the end we go to the previous room and create new paths
	{	arr[crow][ccol].travel=true;		//shows that the end is pathed
		if(box[crow][ccol].prevdir=="up")
		{
			generatemaze(arr, crow+1, ccol);		//if the current room holds "up" as its previous
		}											//direction then you must go down to go back to it
		else if(arr[crow][ccol].goback=="SOUTH")
		{
			generatemaze(arr, crow-1, ccol);
		}
		else if(arr[crow][ccol].goback=="WEST")
		{
			generatemaze(arr, crow, ccol+1);
		}
		else if(arr[crow][ccol].goback=="EAST")
		{
			generatemaze(arr, crow, ccol-1);
		}
	}
	
	/* this start checking for walls if you are in the top
		corner of the maze */

	if(crow==0)
	{				
		GONORTH=false;
		direc--;		//if a possible direction is deemed false this means the number 
	}						//of directions you can go is one less
	if(crow==row-1)
	{
		GOSOUTH=false;
		direc--;
	}
	if(ccol==0)
	{
		GOWEST=false;
		direc--;
	}
	if(ccol==col-1)
	{
		GOEAST=false;
		direc--;
	}	
	/*This checks if you have already been in the cell that has been generated
		with the wall or not */
	if(GONORTH)
	{
		if(arr[crow-1][ccol].travel)
		{
			GONORHT=false;
			direct--;
		}
	}
	if(GOSOUTH)
	{
		if(arr[crow+1][ccol].travel)
		{
			GOSOUTH=false;
			direc--;
		}
	}
	if(GOWEST)
	{
		if(arr[crow][ccol-1].travel)
		{
			GOWEST=false;
			direc--;
		}
	}
	if(GOEAST)
	{
		if(arr[crow][ccol+1].travel)
		{
			GOEAST=false;
			directions--;
		}
	}

	//here there are two options, if the number of directions you can go is not 0 then a random number is picked
	//to match one of the direction numbers (i.e. numup, numdown..) and based on the direction number and random
	//number a direction is chosen and through recursion the coordinates for the next room is sent to the function

	//option two is if there are no possible directions you can go, you must go back. so through the prevdir variable
	//in the "room" class, it goes back to the room it was in before the current room

	if(direc!=0)
	{
		randomdir=rand()%direc;
		if(randomdir==numup)
		{
			//cout << "up" << endl;
			arr[crow][ccol].travel=true;		//shows I have been here
			arr[crow][ccol].NORTH=false;		//turns off corresponding wall to open a path
			arr[crow-1][ccol].SOUTH=false;
			arr[crow-1][ccol].goback="NORTH";		//assigns what direction youre going to the next room
			generatemaze(arr, crow-1, ccol);		//recursion
		}
		else if(randomdir==numdown)
		{
			//cout << "down" << endl;
			arr[crow][ccol].travel=true;
			arr[crow][ccol].SOUTH=false;
			arr[crow+1][ccol].NORTH=false;
			arr[crow+1][ccol].goback="SOUTH";
			generatemaze(arr, crow+1, ccol);
		}
		else if(randomdir==numleft)
		{
			//cout << "left" << endl;
			arr[crow][ccol].travel=true;
			arr[crow][ccol].WEST=false;
			arr[crow][ccol-1].EAST=false;
			arr[crow][ccol-1].goback="WEST";
			generatemaze(arr, crow, ccol-1);
		}
		else if(randomdir==numright)
		{
			//cout << "right" << endl;
			arr[crow][ccol].travel=true;
			arr[crow][ccol].EAST=false;
			arr[crow][ccol+1].WEST=false;
			arr[crow][ccol+1].goback="EAST";
			generatemaze(arr, crow, ccol+1);
		}
	
	}	/* if been to the cell, go back to the previous one and continue
			on to the next available one */
	else if(direc==0)
	{
		if(arr[crow][ccol].goback=="NORTH")
		{
			arr[crow][ccol].travel=true;		
			generatemaze(arr, crow+1, ccol);		
		}											
		else if(arr[crow][ccol].goback=="SOUTH")
		{
			arr[crow][ccol].travel=true;
			generatemaze(arr, crow-1, ccol);
		}
		else if(arr[crow][ccol].goback=="WEST")
		{
			arr[crow][ccol].travel=true;
			generatemaze(arr, crow, ccol+1);
		}
		else if(arr[crow][ccol].goback=="EAST")
		{
			arr[crow][ccol].travel=true;
			generatemaze(arr, crow, ccol-1);
		}
	}
   
}

Looking at your printmaze function it looks very likely that you have missed some matching opening and closing braces somewhere. Just try and ensure that.

Wow, you have functions that are +100 lines long... This would be a good time to consider using the inline qualifier and break these large functions into smaller, neater inline functions.

thank you for the advice on my printmaze function. it helped! yes i know its a lot of code but i'm trying my best to get it to work a maze. Once I get better at it I can go back and update it to be smaller.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.