Question: #include #include #include #include using namespace std; void printit ( int data [ 5 ] [ 5 ] ) { for ( int i =

#include
#include
#include
#include
using namespace std;
void printit(int data[5][5]){
for (int i =0; i <5; i++){
for (int j =0; j <5; j++){
cout << data[i][j]<<"";
}
cout << endl;
}
cout << endl;
}
void clear(int data[5][5]){
for (int i =0; i <5; i++){
for (int j =0; j <5; j++){
data[i][j]=0;
}
}
}
int main(){
string sentence;
string firstword;
int x;
int row, col;
int args;
int arr[5][5];
cout <<"u # will move the one up # times" << endl;
cout <<"d # will move the one down # times" << endl;
cout <<"l # will move the one left # times" << endl;
cout <<"r # will move the one right # times" << endl;
cout << "exit will leave" << endl << endl;
clear(arr);
arr[2][2]=1;
printit(arr);
row =2;
col =2;
while (true){
cout << "enter your command>";
getline(cin, sentence);
args = sscanf_s(sentence.c_str(),"%s %d", firstword.c_str(),(unsigned)firstword.length(), &x);
if (firstword == "exit"){
cout << "goodbye" << endl;
break;
}
else if (firstword =="u"|| firstword =="d"|| firstword =="l"|| firstword =="r"){
if (args <2) x =1;
cout << "row is "<< row <<" col is "<< col << endl;
for (int i =0; i < x; i++){
if (firstword =="u"){
row =(row -1+5)%5; // Ensure it wraps around if it goes negative
}
else if (firstword =="d"){
row =(row +1)%5;
}
else if (firstword =="l"){
col =(col -1+5)%5; // Ensure it wraps around if it goes negative
}
else if (firstword =="r"){
col =(col +1)%5; // Ensure it wraps around if it goes beyond the last column
}
clear(arr);
arr[row][col]=1;
printit(arr);
}
}
else {
cout << "don't understand that" << endl;
}
}
return 0;
} Help fix my code please I want my output to be able to Do a
l 3(goes left and prints the matrix a total of three times (notice how it should wrap around) to the right
Then do a
u 2(goes up and prints the matrix a total of two times)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!