Here is the problem once i initialise the n x n area of maze in array ,i cannot correctly specific the exact location of the robot starting point to move
#include <iostream>
#include <conio.h>
#include <iomanip>
usingnamespace std;
int main()
{
int n,column,row;
char square[n][n];
cout <<"Set the value of n x n squares area:"<<endl;
cout <<"Enter the value for first n:";
cin >> n;
for(int x=0;x<n;x++)
{
for(int y=0;y<n;y++)
{
square[x][y]='#';
}
}
for(int x=0;x<n;x++)
{cout<<setw(7);
for(int y=0;y<n;y++)
{
cout << square[x][y];
}
cout<<endl;
}
cout <<"Now specific the robot starting point to move:"<<endl;
cout <<"Enter which column:(starting from 0)";
do{
cin >> column;
if(column > (n-1))
cout<<"The column size is more than the square areas,please enter again:";
}while(column>(n-1));
cout <<"Enter which row:(starting from 0)";
do{
cin >> row;
if(row > (n-1))
cout<<"The column size is more than the square areas,please enter again:";
}while(row >(n-1));
cout<<"The row is "<<row<<endl;
cout<<"The column is "<<column<<endl;
square[4][4]='*';
for(int x=0;x<n;x++)
{cout<<setw(7);
for(int y=0;y<n;y++)
{
cout << square[x][y];
}
cout<<endl;
}
getch();
return 0;
}
the final output did not correctly match the location of starting point of column and row.For example when i key in the value of 2 for both row and column,
the * symbol which use as a robot would emerge in several places.Why?