another maze problem

i had construct another maze which i could setup the n x n with user input successfully.The problem is i cannot correctly specify the visited area with 'R',which is a symbol of a robot.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <vector>

using namespace std;


void movement(vector<vector<char> >,int,int);
int n,colsend,rowend;
int main()
{

int column,row;


cout <<"Set the value of n x n squares area:"<<endl;
cout <<"Enter the value for n:";
cin >> n;
vector<vector<char> > square(n,vector<char>(n,'.'));
cout<<"\n\n";

for(int x=0;x<n;x++)
{cout<<setw(7);
for(int y=0;y<n;y++)
{
cout << square[x][y];
cout<<setw(3);
}
cout<<endl;
}
cout<<"\nThis is the square area robot could move."<<endl;
cout <<"\nNow specific the robot starting point and destination to move:"<<endl;
cout <<"Enter which column to start(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 column to end(starting from 0) :";
do{
cin >> colsend;
if(colsend > (n-1))
cout<<"The column size is more than the square areas,please enter again:";
}while(colsend>(n-1));



cout <<"Enter which row to start(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 <<"Enter which row to end(starting from 0) :";
do{
cin >> rowend;
if(rowend > (n-1))
cout<<"The column size is more than the square areas,please enter again:";
}while(rowend >(n-1));


cout<<"The row and column of the starting point is ("<<row<<","<<column<<")"<<endl;
cout<<"The row and column of the destination is ("<<rowend<<","<<colsend<<")"<<endl;

square[row][column]='R';
square[rowend][colsend]='X';
for(int x=0;x<n;x++)
{cout<<setw(7);
for(int y=0;y<n;y++)
{
cout << square[x][y];
cout<<setw(3);
}
cout<<endl;
}
cout <<"\n(. is square)         (R is robot)";
movement(square,row,column);



getch();
return 0;

}

void movement(vector<vector<char> >square,int ro,int col)
{    
     char direction;
     int numsquare;
     int temp = 0;
     
     
     
     cout <<"\nNow specific the movement, press:"<<endl;
     cout <<"w for move up."<<endl;
     cout <<"s for move down."<<endl;
     cout <<"d for move right."<<endl;
     cout <<"a for move left."<<endl;
     do{
     cin >> direction;
     if(direction=='w')
     {
                    cout<<"How many square you want to move up:";
                    do{
                    cin >>numsquare;
                    if((ro-numsquare)<0)
                    cout <<"The number of square is not in the range,enter again:";
                    }while((ro-numsquare)<0);
                    
                    while(temp!= numsquare)
                    {        
                             ro-=1;
                             square[ro][col] = 'R';
                             temp++;
                             }
                             cout<<endl;
                             for(int x=0;x<n;x++)
                             {cout<<setw(7);
                             for(int y=0;y<n;y++)
                             {
                             cout << square[x][y];
                             cout<<setw(3);
                             }
                             cout<<endl;
                             }
                             
                             }
                                 
                                 
                                 cout<<"\nRowend value is "<<rowend<<endl;
                                 cout<<"\nRow value is"<<ro<<endl;
                                 if(ro!=rowend)
                                 {
                                 cout <<"Not reach yet.Enter the square again:";
                                 }
                                 
                                 }while(ro!=rowend);
                                 }
                                                         
                                 
                                 
                             


For example w is a part of direction to move upward of the 'R',in the maze.But the loop seems cannot remember the math operation on the ro variable to test whether it matching with rowend variable value.Anything i could done so the 'R' symbol could correctly place on the maze?
Topic archived. No new replies allowed.