interesting problems

ok, im making a function that is supposed to solve a maze. the display function works and everything else works, except the solve. the code for the solve function is included below.

void solve (char b[100][100], int row, int col)
{
int i = 1;
int j = 1;

while (i < row && j < col)
{
cout << b[i][j] << endl;
if (b[i+1][j] = 32)
{
b[i][j] = 46;
i++;
}
else if (b[i][j+1] = 32)
{
b[i][j] = 46;
j++;
}
else if (b[i-1][j] = 32)
{
b[i][j] = 46;
i--;
}
else if (b[i][j-1] = 32)
{
b[i][j] = 46;
j--;
}
else
{
if (b[i][j-1] = 46)
{
b[i][j] = 120;
i++;
}
else if (b[i-1][j] = 46)
{
b[i][j] = 120;
j++;
}
else if (b[i][j+1] = 46)
{
b[i][j] = 120;
i--;
}
else if (b[i+1][j] = 46)
{
b[i][j] = 120;
j--;
}
}
}

for(int k = 0; k < row; k++)
{
for(int p = 0; p < col; p++)
{
if (b[i][j] = 'x')
{
b[i][j] = ' ';
}
}
}
}
basically it looks to the right, left ect. and if there is a space it fills the current spot with a '.' and then moves to the next spot and repeats as seen in the if statements. makes sense right.

i would show you the actually maze and what is solves it too, but it doesnt show up properly here. the problem is that it wont put down any periods and it changes the maze around.
Last edited on
When using if/else statements you need to use the '==' symbol. = is used for directly assigning values.
that didnt help. it actually caused an infinite loop. since im comparing it to the ascii value, i should be able to use just '='. if i actually did the symbol that would make sense. but either way it doesnt solve the problem. anything else wrong with it? please help me.
What is the meaning of 32, 46 and 120? You could use named constants instead of the magic numbers to make it easier to understand what it means.
using just '=' doesnt compare anything at all, writing if(x = 2){} sets x equal to 2, it doesnt compare anything. In order to compare something you need '==' , if it runs an infinite loop it must be your code, not the syntax thats wrong.
Topic archived. No new replies allowed.