-
Maze Project
Hey guys im new to the board and need some help with this path finding project iv gata make for class.
Ok first u need to know what the project intails. I have to write a dos orented program that reads in a .txt file with a maze made up of x's and o's. The x's represent the walls and the o's are open spaces. The program must then print out in a .txt file what moves where taken to reach the cheese. O and there is an m (for mouse) and c (for cheese). Here is an example of how the program should look;
2 left
1 down
3 right
1 up
Stuff like that.
Iv already figured out how to read in the file....print out the output to the .txt file and I think (note i said think) I figured out how to make the engine to move squares.
But now I can't seem to impliment the search engine into the map. First problem I need to figure out a way to set up the maze (witch is 20x20 so 400 squares) in an array with out having to write 400 statements.
Ill wait to ask the second question until someone replies.....just in case if figure out the second question after getting the first one answered.
O any web sites that coudl help? Thanx in advance.
-
Reading the array is simple enough:
Code:
for ( int i = 0; i < 20; ++i )
for ( int j = 0; j < 20; ++j )
file>>maze[i][j];
Finding a path through the maze is more difficult, but the solution is simpler if you use recursion. That way you can move through all possible paths and if you hit a wall, simply return to the last path where you had an untried option.
-Prelude
-
-
Ok i read what yall wrote and i basically hit myselft in the head...because i had it setup like that and deleted it. Ok the second quesiton is.....i want to print all them out...but cout << maze[i][j]; wont print anything. how can i print out the entire .txt maze file?
O and the thrid question. My professor said to take the 'c' varibale and make it 0 and then number each square according to how many steps it takes to get to the cheese. Then make a loop that counts down to each open square to 0. But how do u give each square a letter?
O and code isnt nessicary. If u have examples yeah. but you can juz tell me in words what kinda stuff i would need.. That way i can learn it better. Thanx for the help.
-
wow that sounds like an excellent excercise to try.
I think I may have to try that one myself!
Is your class a beginners programming class?
-
Yeah im taking 1st semester programming. And i havent programmed anything for about 3 years..So I really need some help. And this program is due tomorrow at 2:30.soo
-
O and i ment to give each square a number. Sorry for the typo.
Now since my time is running out im going to go ahead and ask for some help determaning weather the step was up, down, left, or right. I already know how to print it out. What i need to know is how to actually write the part that determines what direction im going in. So if yall could help me answer these questions, i would apreacate it.
-
Tell me what you think about this. Would it work if i took the character M and place it inside of an while loop that would count down to the next number as long as M doesn't equeal zero?
And if this would work. What would I set M to? Because I can't set it to 0. So do i find the area in the maze where it is or what? What do yall think?
-
Code:
void demo()
{
int l, w;
for (w = 0; w < 20; ++w)
{
for (l = 0; l < 20; ++l)
{
InMaze >> maze[w][l];
if (maze[w][l] == 'x')
maze[w][l] = border;
else
if (maze[w][l] == 'o')
maze[w][l] = open;
}
}
while ( m != 0 )
{
char nextstep;
nextstep = open;
if ( nextstep == border )
nextstep == false;
else
if ( nextstep == true )
m--;
}
}
would this code work to find the next avaible square? I really don't know of any way to test it. What do yall think?
Code tags added by Kermi3
-
Code Tags
I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you ;)
For example:
Without code tags:
for(int i=0;i<5;i++)
{
cout << "No code tags are bad";
}
With Code Tags:
Code:
for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}
This is of course a basic example...more complicated code is even easier to read with code tags than without.
I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.
-
Test it by inputting a small maze, like only 3x3 with an answer you know for sure. Then see what it does. heh it's simple but it woks.
-
You see i thought about doing that....but i still need one question answered. What do i set M to? Because if i set it to 0 the program will think that it is salved. So do i set m to it position on the map or what?
-
Ok guys i inputted a smaller maze that i knew the answer to and added this code
Code:
while ( m != 0 )
{
char nextstep;
nextstep = open;
if ( nextstep == border )
nextstep == false;
else
if ( nextstep == true )
m--;
cout << nextstep << endl;
cout << m << endl;
Maze << m << nextstep;
}
}
but all i get back is jibberish. It looks like black squares. Why does it do this?
-
well to start with I can's see a time when nextsp would ever equal boarder...the other thing is the way I'm reading it you're using the same nextstep evertime. How is it supposed to change?
-
So you mean nextstep should change position or value? And yeah i thought that nextstep equaling boarder wouldnt work. But im getting confused. What im trying to say is that if the nextstep is into a wall then don't take that step. How should I word it?
-
you're going to need something...
well here's your problem:
Your mouse has to be able to look in four directions doesn't it? So you have to look and see where it can fo. Then you have to see:
Code:
nextstep[x][y]=maze[w][l]
//then in a loop:
if (nextstep[x][y+1]==open)
nextstep[x][y]=nexstep[x][y+]
I'm not sure that's the best way to do it. But that's one way...it need additions and more work but...a start.
-
Code:
char nextstep;
char xpos = 30;
do
{
for (m = xpos; m >= 1; m--)
{
if (maze[w][l] == 'x')
nextstep = false;
else
if (maze[w][l] == 'o')
nextstep == m--;
cout << m << endl;
}
}while ( m != 0);
Ok what im thinking is that this code is going to calculate the nextmove of m. Tell me if you think this works. Now all im trying to do at this point is get it to move if the nextsquare is an 'o' and not move if the next square is 'x'. The loop will tell it to keep going until it reaches 0. What i need to do now to make it work with the maze is to tell it where 'M' is. How can i do that? I know I can't use 30. Any suggestions?
-
Ok kermi. Now you got me thinking. I didnt know i could use nextstep like nextstep[x][y]. Now i know what your saying. But one question still haunts me. How do i set up M? I mean i have to give a position and my teacher is going to use differant mazes for this program. any suggestions?
-
Ok i understand you dont want to spend your sunday night helping me, but Iv really got to get this done. So here is a really stupid question. exactly what does the x and y mean in the array? What are they standing for? I think the x and y is the differant sides of the mouse...or its so the size of the maze can be stored in it. Is that any where close? And can you answer my other question above?
-
Code:
void demo()
{
int l, w;
char border = 0;
char open = 1;
for (w = 0; w < 20; ++w)
{
for (l = 0; l < 20; ++l)
{
InMaze >> maze[w][l];
if (maze[w][l] == 'x')
maze[w][l] = border;
else
if (maze[w][l] == 'o')
maze[w][l] = open;
else
if (maze[w][l] == 'm')
maze[w][l] = m;
else
if (maze[w][l] == 'c')
maze[w][l] = c;
}
}
char nextstep=m;
do
{
if (nextstep+1==open)
{
nextstep=nextstep++;
cout << nextstep << endl;
}
}while ( m != 0);
Can anyone tell me why this code produces a single odd symbol? I think I set it up right. Basically what im trying to do is tell the program to search for the letter 'm' and then start trying to find the next square. But all I get out is a really weird symbol. Any comments?
-
you need to give m a posistion. and have it move around. take a piece of paper. draw a maze on it:
0 1 2
+------
0| X 0 X
1| X 0 X
2| 0 0 X
Say your mouse starts at mx=0 my=2
then you have to say, is there an open move for me to go to? Is there one to the North? mx,my-1 no. Is there one to the East? mx+1,my
yes. mx = mx+1
Now repeat. You'll run into problems with this is when your mouse tries to check to the south for exmple here. You go out of the array. You have to have a variable of max rows and max cols, so that you never check if your mx or my will go past that value.
That's one method. Not sure if it's the best but...
My bed time now...good luck
-
thank you. I truly appreaciate the help man.
-
Code:
void demo()
{
int x=8;
int y=8;
int l, w;
char border = 0;
char open = 1;
for (w = 0; w < 20; ++w)
{
for (l = 0; l < 20; ++l)
{
InMaze >> maze[w][l];
if (maze[w][l] == 'x')
maze[w][l] = border;
else
if (maze[w][l] == 'o')
maze[w][l] = open;
else
if (maze[w][l] == 'm')
maze[w][l] = mouse[x][y];
else
if (maze[w][l] == 'c')
maze[w][l] = c;
}
}
do
{
if (mouse[x][y-1]==open)
{
mouse[x][y]=mouse[x][y--];
cout << y << endl;
}
else
if (mouse[x][y+1]==open)
{
mouse[x][y]=mouse[x][y++];
cout << y << endl;
}
else
if (mouse[x-1][y]==open)
{
mouse[x][y]=mouse[x--][y];
cout << x << endl;
}
else
if (mouse[x+1][y]==open)
{
mouse[x][y]=mouse[x++][y];
cout << x << endl;
}
}while ( mouse[x][y] != 0);
if (m == 0)
cout << "maze finished" << endl;
}
God I hope someone is online. Ok this code is correct i think. But for some reason I dont get any output from where it says stuff like "cout << x << endl;"
Any one know why nothing shows up?
-
I'll help but I'm a little confused. It looks like you want this mouse to move to any space it finds empty until it gets through the maze?
First off, I'm seeing a lot of variables that I'm not sure about...
if (m == 0)
Whats m?
'maze' I'm assuming would be the array that contains the maze... 'mouse' is what exactly? Why is it a 2D array? Shouldnt your mouse be represented by x and y variables inside the maze?
Oh, and earlier in your code I noticed this:
if (maze[w][l] == 'o')
nextstep == m--;
I notice it disapears later, so I'm not sure if this was just a mistake but the '==' operator is for comparison and the '=' operator is for assigning. That should have been this:
if (maze[w][l] == 'o')
nextstep = m--;
Just for future reference.
If you can clear up my questions I'll be hanging around to help (for a while, and at times).
-
Ok the m stands for mouse. I think im going to get rid of it. Ill post my entire source so you can see everything. I have the mouse being a 2d array because the dud kermi suggested it. Here is my source.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
ifstream InMaze;
ofstream Maze;
void reading();
void demo();
void demo2();
char m;
char c = 0;
char maze[20][20];
char mouse[20][20];
int main ()
{
cout << " Welcome to THE MAZE " << endl;
cout << "This program doenst work!" << endl;
cout << endl;
//reading();
//demo();
return 0;
}
// This is where the data is read into the program
void reading()
{
InMaze.open("maze.txt");
Maze.open("Result.txt");
}
//This is a demo of how the output will be setup
void demo()
{
int x=8;
int y=8;
int l, w;
char border = 0;
char open = 1;
for (w = 0; w < 20; ++w)
{
for (l = 0; l < 20; ++l)
{
InMaze >> maze[w][l];
if (maze[w][l] == 'x')
maze[w][l] = border;
else
if (maze[w][l] == 'o')
maze[w][l] = open;
else
if (maze[w][l] == 'm')
maze[w][l] = mouse[x][y];
else
if (maze[w][l] == 'c')
maze[w][l] = c;
}
}
do
{
if (mouse[x][y-1]==open)
{
mouse[x][y]=mouse[x][y--];
Maze << y;
}
else
if (mouse[x][y+1]==open)
{
mouse[x][y]=mouse[x][y++];
Maze << y;
}
else
if (mouse[x-1][y]==open)
{
mouse[x][y]=mouse[x--][y];
Maze << x;
}
else
if (mouse[x+1][y]==open)
{
mouse[x][y]=mouse[x++][y];
Maze << x;
}
}while ( mouse[x][y] != 0);
if (mouse[x][y] == 0)
cout << "maze finished" << endl;
for (int i = 0; i < 20; i++)
{
for (int a = 0; a < 20; a++)
{
maze[i][a].Write();
cout << endl;
}
}
}
Now the maze array is 2d so it can hold the x and y axis of it. Im really not sure if this is right. Im juz kinda going blindly into the night. Any suggestions?
O and the mouse needs to find the shorest path. I plan on adding a recurring algorithm later on. But right now im stuck. Please help. THanx
-
for the love of god can some one give me a hand
-
This is just an example. It wont work because theres no algorithm for finding the path, the mouse will just move back and forth. I just typed this up in notepad but i dont see anything wrong with it. Should compile fine. I created a temporary maze variable that I filled with the worlds simplest maze to demonstrate. You'll obviously want to read your own data into 'maze' before you call your demo function.
Tell me if this was what you're looking for... I'm still a little confused.
//I wont argue about your use of iostream as its a matter of
//preference but I'll leave all input as-is. I assume your supposed
//to use iostream anyhow so I wont make suggestions about better
//alternatives. Its my own opinion anyways...
Code:
//We define the size of the Maze here so if it changes,
//we can alter it easily and in one place only
#define SizeOfMazeX 10
#define SizeOfMazeY 10
//different states the any element of the maze may be in
#define BORDER 0
#define OPEN 1
#define BLOCKED 2
//The Maze array
char maze[SizeOfMazeX][SizeOfMazeY] =
{
'x','x','x','x','x','x','x','x','x','x',
'x','o','o','o','o','o','o','o','o','x',
'x','o','o','o','o','o','o','o','o','x',
'x','o','o','o','c','c','c','o','o','x',
'x','o','o','o','c','m','c','o','o','x',
'x','o','o','o','c','o','c','o','o','x',
'x','o','o','o','c','o','c','o','o','x',
'x','o','o','o','c','o','c','o','o','x',
'x','o','o','o','c','o','c','o','o','x',
'x','x','x','x','x','x','x','x','x','x',
};
//The position of our little rodent (0 by default)
char MouseX = 0, MouseY = 0;
int main (void)
{
int x, y;
//Apparently we want to take the maze and convert its contents
//into Wall/Open/Exit data.
for (x = 0; x < SizeOfMazeX; x++)
{
for (y = 0; y < SizeOfMazeY; y++)
{
//I dont know why we're doing this but we're doing it anyhow
//We could just as easily compare the character values later
//instead of converting them to these predefined values...
//Any reason you do this?
//print out each element of the array (to show the maze)
cout << maze[x][y];
if (maze[x][y] == 'x')
maze[x][y] = BORDER;
else if (maze[x][y] == 'o')
maze[x][y] = OPEN;
else if (maze[x][y] == 'm')
{
//I assume that the 'm' is where we want the mouse
//to start. So we assign our Mouse coordinates to
//the position we're currently reading
MouseX = x;
MouseY = y;
//We'll, the mouse starts here so I assume its open...
maze[x][y] = OPEN;
}
else if (maze[x][y] == 'c')
maze[x][y] = BLOCKED;
}
//move to next line
cout << endl;
}
do
{
//Move around
//IMPORTANT: This wont work to solve the maze in any way.
//This is just an example. You said you would do your own
//algorithm to solve this. This just moves the mouse to
//the first empty space it finds near it. Using this code
//will just make the mouse run around in circles (back and
//for, back and forth). Put your own algorithm here.
if (maze[MouseX][MouseY-1] == OPEN)
MouseY --;
else if (maze[MouseX][MouseY+1] == OPEN)
MouseY ++;
else if (maze[MouseX-1][MouseY] == OPEN)
MouseX --;
else if (maze[MouseX+1][MouseY] == OPEN)
MouseX ++;
}while (maze[MouseX][MouseY] != BORDER);
// if (maze[x][y] == 0)
//We dont need to check that because if we got out of the
//while loop than we obviously reached the BORDER
cout << "maze finished" << endl;
return 0;
}
-
Apologies on something. All these lines:
if (maze[MouseX][MouseY-1] == OPEN)
should instead be:
if (maze[MouseX][MouseY-1] != BLOCKED)
otherwise mousey will never reach an exit square since its not technically "open".
(That and to note that I changed to maze size from 20 to 10 for this example because it was easier to type in a 10x10 maze than a 20x20. Call me lazy. Just change the #defines for your own program.)
-
I have a question. In that example code you wrote you made the x's equal the BORDER and the c is equal to blocked. Why? During this program you wrote if the mouse reaches a 'x' then the program will end. I need to program to end when the mouse reaches the 'c'. so i think instead of using that loop you should have put c equal to finish and the make the do loop say. Do once then check if the mouse has reached the finish (or cheese), and then just take out the border. I think that would be right. What do u think?
-
Ahh, sorry, I misinterpreted your values. Your assumptions are correct. Re-written correctly (with the cheese and no borders):
Code:
//We define the size of the Maze here so if it changes,
//we can alter it easily and in one place only
#define SizeOfMazeX 10
#define SizeOfMazeY 10
//different states the any element of the maze may be in
#define CHEESE 0
#define OPEN 1
#define BLOCKED 2
//The Maze array
char maze[SizeOfMazeX][SizeOfMazeY] =
{
'x','x','x','x','x','x','x','x','x','x',
'x','o','o','o','o','o','o','o','o','x',
'x','o','o','o','o','o','o','o','o','x',
'x','o','o','o','x','x','x','o','o','x',
'x','o','o','o','x','m','x','o','o','x',
'x','o','o','o','x','o','x','o','o','x',
'x','o','o','o','x','o','x','o','o','x',
'x','o','o','o','x','o','x','o','o','x',
'x','o','o','o','x','c','x','o','o','x',
'x','x','x','x','x','x','x','x','x','x',
};
//The position of our little rodent (0 by default)
char MouseX = 0, MouseY = 0;
int main (void)
{
int x, y;
//Apparently we want to take the maze and convert its contents
//into Wall/Open/Exit data.
for (x = 0; x < SizeOfMazeX; x++)
{
for (y = 0; y < SizeOfMazeY; y++)
{
//I dont know why we're doing this but we're doing it anyhow
//We could just as easily compare the character values later
//instead of converting them to these predefined values...
//Any reason you do this?
//print out each element of the array (to show the maze)
cout << maze[x][y];
if (maze[x][y] == 'x')
maze[x][y] = BLOCKED;
else if (maze[x][y] == 'o')
maze[x][y] = OPEN;
else if (maze[x][y] == 'm')
{
//I assume that the 'm' is where we want the mouse
//to start. So we assign our Mouse coordinates to
//the position we're currently reading
MouseX = x;
MouseY = y;
//We'll, the mouse starts here so I assume its open...
maze[x][y] = OPEN;
}
else if (maze[x][y] == 'c')
maze[x][y] = CHEESE;
}
//move to next line
cout << endl;
}
do
{
//Move around
//IMPORTANT: This wont work to solve the maze in any way.
//This is just an example. You said you would do your own
//algorithm to solve this. This just moves the mouse to
//the first empty space it finds near it. Using this code
//will just make the mouse run around in circles (back and
//for, back and forth). Put your own algorithm here.
if (maze[MouseX][MouseY-1] != BLOCKED)
MouseY --;
else if (maze[MouseX][MouseY+1] != BLOCKED)
MouseY ++;
else if (maze[MouseX-1][MouseY] != BLOCKED)
MouseX --;
else if (maze[MouseX+1][MouseY] != BLOCKED)
MouseX ++;
}while (maze[MouseX][MouseY] != CHEESE);
cout << "maze finished" << endl;
return 0;
}
Does this help now? It still wont work because theres no mouse moving algorithm, but you said you have that covered...
-
Ok i have anouther question. This one stumps me. Does the fstream fuctions "file.open(file.txt)" not work with #define? I keep getting 98 errors and then i took away the #define stuff and only errors i got where ones i would expect from values not being identified. Whats going on?
-
A #define will work simular in function to a variable that you cannot change. Your compiler will change all occurances in your code from 'SizeOfMazeX' to '10' before it compiles your code. Its just an easy way to keep track of things. Without the define, if we were to change the size of the maze we would have to change all the for...loops as well as the definition of the maze array. This makes life easier (and safer).
You shouldnt be getting any errors... Unless your trying to change the value of SizeOfMazeX or SizeOfMazeY? Possibly by reading to them from a file?
-
ok file is 400 characters long.....meaning 20x20. I already set the size of maxX to 20 and size of maxY to 20. yet i still get error messages. I dont get it.
-
Could you post your updated code in full?
-
C:\Program Files\Microsoft Visual Studio\MyProjects\Project 2\Main.cpp(29) : error C2039: 'Maze' : is not a member of 'basic_ifstream<char,struct std::char_traits<char> >'
thats one of them.
-
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
#define maxX 20;
#define maxY 20;
#define border 0;
#define open 1;
#define blocked 2;
#define finish 3;
char mouseX = 0;
char mouseY = 0;
char maze[maxX][maxY];
ifstream InMaze;
ofstream Maze;
int main (void)
{
InMaze.open("maze.txt");
Maze.open("result.txt");
int x, y;
if (maze[x][y] == 'x')
maze[x][y] = border;
else if (maze[x][y] == 'o')
maze[x][y] = open;
else if (maze[x][y] == 'm')
{
mouseX = x;
mouseY = y;
maze[x][y] = open;
}
else if (maze[x][y] == 'c')
maze[x][y] = finish;
do
{
if (maze[mouseX][mouseY-1] != blocked)
mouseY --;
else if (maze[mouseX][mouseY+1] != border)
mouseY ++;
else if (maze[mouseX-1][mouseY] != border)
mouseX --;
else if (maze[mouseX+1][mouseY] != border)
mouseX ++;
}while (maze[mouseX][mouseY] != blocked);
return 0;
}
/*
void ****()
{
int x, y;
for (x = 0; x < maxX; x++)
{
for (y = 0; y < maxY; y++)
{
InMaze >> maze[x][y];
}
}*/
-
im thinking visual studio has been running to long. Mabe I should restart it. I dunno.
-
Right away I notice something. #defines are not terminated with a semi-colan.
This:
#define maxX 20; //<--- Semi-Colan = bad
should be this:
#define maxX 20
That should solve it... Works now?
P.S. I'm having the occasional problem connecting to cprogramming.com right now.... not sure why. Replies may become delayed or cease completly. This submission has failed 3 times already... waiting.... still waiting... we'll see what happens...
-
I now have 80 errors. It went down 18 error messages.
-
its saying that damn neer every varable is not a member of the ifstream char, struct, and all kinds of other stuff.
-
They all relate to your use of iostream:
ifstream InMaze;
ofstream Maze;
InMaze.open("maze.txt");
Maze.open("result.txt");
I dont have time to explain all that stuff, I'm sorry. Its 12:30 here and I'm one of those poor SOBs that have to get up at 6:30 and go to work. You might want to look up info on file I/O. Check out fopen, fread, and fwrite for (In my opinion) a superior method of file I/O... unless as I suspect, you're required to use iostream... Then look for an iostream tutorial (i'll try to find you one).
Also, you cant do this:
int x, y;
if (maze[x][y] == 'x')
maze[x][y] = border;
else if (maze[x][y] == 'o')
maze[x][y] = open;
else if (maze[x][y] == 'm')
x and y aren't set to anything so we dont know what element of the array we're accessing. It will crash. At least do this:
int x = 0, y = 0;
but I think you want to reset _all_ the maze so you need to loop through it like before:
for (x = 0; x < SizeOfMazeX; x++)
and all that stuff.
-
A couple of tutorials on iostream on this page:
http://www.programmersheaven.com/zone3/cat34/
scroll down to find them. Dont know if they're good or not, I just did a search.
/* Edit */
I'm afraid I must retire. I'll help again tomorrow if you still require it then. Good luck.
-
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#define maxX 20
#define maxY 20
void readin();
void maze();
ifstream InFile;
ofstream Outfile;
char mazey[maxX][maxY];
int main (void)
{
cout << "This is my maze program!" << endl;
cout << "All information will be printed to the result.txt file" << endl;
readin();
maze();
return 0;
}
void readin()
{
InFile.open("maze.txt");
Outfile.open("result.txt");
}
void maze()
{
int x = 0;
int y = 0;
char open=1;
char border=0;
char cheese=3;
char mouseX=0;
char mouseY=0;
for (x = 0; x < maxX; x++)
{
for (y = 0; y < maxY; y++)
{
InFile >> mazey[x][y];
if (mazey[x][y]=='x')
mazey[x][y] = border;
else
if (mazey[x][y]=='o')
mazey[x][y] = open;
else
if (mazey[x][y]=='m')
{
mouseX = x;
mouseY = y;
mazey[x][y] = open;
}
else
if (mazey[x][y]=='c')
mazey[x][y] = 0;
do
{
if (mazey[mouseX][mouseY-1] != border)
{
mouseY--;
Outfile <<mouseY;
}
else
if (mazey[mouseX][mouseY+1] != border)
{
mouseY++;
Outfile << mouseY;
}
else
if (mazey[mouseX-1][mouseY] != border)
{
mouseX--;
Outfile << mouseX;
}
else
if (mazey[mouseX+1][mouseY] != border)
{
mouseX++;
Outfile << mouseX;
}
}while (mazey[mouseX][mouseY] != 0);
}
}
}
can anyone help me with this? Any one know whats wrong with this code?
-
Plenty. First off, whats this:
if (mazey[x][y]=='c')
mazey[x][y] = 0;
You're assigning this element a value of 0 which is the same value as your border. You are, in effect, saying
if (mazey[x][y]=='c')
mazey[x][y] = border;
Which we know is bogus since 'x' is your borders. Change that to = cheese.
Second, you're closing braces for your for...loops are in the wrong place.
}while (mazey[mouseX][mouseY] != 0);
} //<----- Move these guys up to
} //<----- just above the do statement.
Third; did you check out those tutorials on iostream? Were they any good? I'm just on a break here and only have a few seconds, so I'm afraid I still cant dedicate much time, sorry...
-
Um na those tutorials where'nt as good as my book. So i looked that stuff up. that maze[x][y]=0 was a typo. I forgot to take it out, i meant cheese. and where should have the loop been?
-
Should be like this:
Code:
for (x = 0; x < maxX; x++)
{// <---- opening brace A
for (y = 0; y < maxY; y++)
{// <---- opening brace B
//stuff here
}// <---- closing brace B
}// <---- closing brace A
do
{
//stuff here
}while (mazey[mouseX][mouseY] != 0);
So you have the iostream stuff figured out? You still getting errors?