What is wrong with the code

#include
using namespace std;
bool ratinmaze(char maze[10][10],int soln[][10],int i,int j,int m,int n)
{
if(i==m && j==n)
{
soln[m][n]=1;
for(int i=0;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
cout<<soln[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
return true;
}
if(i>m || j>n)
{
return false;
}
if(maze[i][j]==‘X’)
{
return false;
}
soln[i][j]=1;
bool right=ratinmaze(maze,soln,i,j+1,m,n);
bool down=ratinmaze(maze,soln,i+1,j,m,n);
soln[i][j]=0;
if(right||down)
{
return true;
}
return false;
}
int main() {
int n,m;
cin>>m>>n;
char maze[10][10];
int soln[10][10]={0};
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>maze[i][j];
}
}
bool ans=ratinmaze(maze,soln,0,0,m-1,n-1);
if(ans==false)
{
cout<<“NO PATH FOUND”;
}
return 0;
}

hello @Kunalgoyal
Assuming u raised doubt for rat chases its cheese problem
read question carefully. in this problem rat can move in all four direction so make changes in code to handel all direction.
also for sharing code :
save ur code here-> https://ide.codingblocks.com/
and then share link with me

yes.

ur doubt is for problem rat chases its cheese and not for rat in a maze right?

ya. i think the code to be same.
update it plz.

no they r not same rat can move in all four direction but u r considering only two directions (for rat chases its cheese).

also there is a mistake in ur right in maze code.
put this condition to make it correct.
image

it is there na. if right or down

but it is after checking both path (right and down).
we need to print right most path so simply if right is returning true then return true .
no need to move down again.

also code for rat chases its cheese-> https://ide.codingblocks.com/s/252898

why u write soln[i][j] in of condition. if(i>m || j>n) this one.

to avoid loop.
because rat is allowed to move in all four direction so it might possible that we visit same place again n again.
to avoid that we are using sol[i][j] .this will tell whether we have visited this state or not if already visited then return false.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.