Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a problem during the code. I want to use system(cls) in the main function but it is not work and the error message

I have a problem during the code. I want to use system("cls") in the main function but it is not work and the error message notify that "sh: cls: command not found". Do you know how to deal with this problem? I will past my code here.

#include  #include  #include  #include  #include  #include  // system("cls"); using namespace std; void create_maze(int &row_robot, int &column_robot ); void show_maze(int row_robot, int column_robot); bool robot_move(int &row_robot, int &column_robot); const int SIZE = 10; enum Values {space, wall, e, robot}; Values maze[SIZE][SIZE]; int main() { srand(static_cast<unsigned int>(time(0))); int row_robot, column_robot, moving; //bool temp = true; row_robot = 4, column_robot = 4; moving = -1; create_maze(row_robot, column_robot); show_maze(row_robot, column_robot); while (maze[row_robot][column_robot]) { ++moving; system("cls"); robot_move(row_robot, column_robot); show_maze(row_robot, column_robot); usleep(1000); cout << "How many moves: " << moving << endl; if (maze[row_robot][column_robot] == e) { break; } } cout << "Robot is survived" << endl; system("pause"); // maze[row_robot][column_robot] = robot; } void create_maze(int &row_robot, int &column_robot) { int i, j; for (i = 0; i < SIZE; i++) for (j = 0; j < SIZE; j++) maze[i][j] = wall; for (i = 1; i < SIZE; i += 3) for (j = 0; j < SIZE; j++) maze[i][j] = space; maze[1][0] = e; maze[7][9] = e; maze[1][9] = wall; maze[4][0] = wall; maze[4][8] = wall; maze[4][9] = wall; maze[7][0] = wall; maze[2][2] = space; maze[2][6] = space; maze[2][8] = space; maze[3][2] = space; maze[5][7] = space; maze[6][3] = space; maze[6][7] = space; maze[row_robot][column_robot] = robot; // Robot describe as 'X' } void show_maze(int row_robot, int column_robot) { int i, j; for(i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) { if (maze[i][j] == 0) cout << " "; else if (maze[i][j] == 1) cout << "+"; else if (maze[i][j] == 2) cout << "e"; else  cout << "X"; } cout <robot; } bool robot_move(int &row_robot, int &column_robot) { unsigned int num; srand((unsigned int)time(0)); num = rand() % 4 + 1; cout << "RANDOM NUMBER: " << num << endl; while (1) { if (num == 1) //Move to North { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; row_robot--; maze[row_robot][column_robot] = robot; break; } } } else if (num == 2) //Move to South { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; row_robot++; maze[row_robot][column_robot] = robot; break; } } } else if (num == 3) //Move to East { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; column_robot++; maze[row_robot][column_robot] = robot; break; } } } else //Move to west { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; column_robot--; maze[row_robot][column_robot] = robot; break; } } } } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions