Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t understand. What variables im i missing 7 7 + +++++ + +++++ + +++++ ++

ID: 3880763 • Letter: I

Question

I don't understand. What variables im i missing

7 7
+ +++++
+ +++++
+ +++++
++ + +++
+   ++++
+++ +++
++++ ++

The program has three functions. One reads a maze into an array. Another finds the path in the maze. And the last one prints the maze with the path. I have been battling with it the whole day but i cant seem to get any output but a zero. If anyone can help ill really appreciate it.


#include
#include
#include

using namespace std;

bool pathfinder(char A[][73], int x, int y, int rowp, int columnp);
void readmaze(ifstream& file, int& row, int& column, char a[][73]);
void printpath(char array[][73], int p, int q);

int main()
{
string filename;
int m, n;
int l=0;
int d=1;
char arr[22][73];

cout << "Enter a filename: -> ";
cin >> filename;

ifstream infile;
infile.open(filename.c_str());
readmaze(infile, m, n, arr);
cout << pathfinder(arr, l, d, m, n);

infile.close();

return 0;

}

void readmaze(ifstream& file, int& row, int& column, char a[][73])
{
char ch;
file >> row >> column;
for (int i=0; i<=row; i++)
{
       for(int j=0; j<=column; j++)
    {
            file.get(a[i][j]);

    }

}
file.get(ch);
}

bool pathfinder(char A[][73], int x, int y, int rowp, int columnp)
{
        int count=0;

        while(A[rowp-1][count]=='+')
            count++;
        if(x==rowp-1 && y==count){
            A[x][y]='@';
            printpath(A, rowp, columnp);
            return true;}

        if (x>=0 && x=0 && y                   A[x][y]='@';
        if(pathfinder(A, x+1, y, rowp, columnp))
                  return true;
        if(pathfinder(A, x-1, y, rowp, columnp))
                  return true;
        if(pathfinder(A, x, y+1, rowp, columnp))
                  return true;
        if(pathfinder(A, x, y-1, rowp, columnp))
                  return true;
       A[x][y]='+';
       return false;
       }
      return false;
}

void printpath(char array[][73], int p, int q)
{
    for(int i=0; i     {
        for(int j=0; j             cout << array[i][j];
    }
    cout << endl;
}

Explanation / Answer

in function pathfinder, you added one if condition which is not at all an executable /valid one.

And that if condition is also not a complete one which you posted.

But here is the wrong that I observered.

if (x>=0 && x=0 && y                   A[x][y]='@';

in above if condition you are trying to check x value (i.e.greater than (x>0) )and at the same time assigned x value with 0 which not a valid case in && (and) operation.

Here you are trying to check x should be >=0 and x should be 0.

AND operation:

In and(&&) operation compiler will execute all the condition.

cases x.=0 x==0/x=0 (x>=0&&x=0)/(x>=0&&x==0) (x>=0||x==0) x=0 true true true true x>0 false true false(always false except x is 0) true