- Maze please use c++ post copy of your code. Be prepared to run your code in cl
ID: 3883331 • Letter: #
Question
- Maze please use c++
post copy of your code. Be prepared to run your code in class.
Write a program that creates a 10 by 10 maze. Represent the maze as an array of characters,
where ‘*’ is a wall. Here is an example:
char maze[10][10] =
{ {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*' },
{'*', '*', ' ', '*', '*', '*', ' ', '*', ' ', '*' },
{'*', '*', ' ', '*', '*', '*', '*', '*', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '*', '*' },
{'*', '*', '*', '*', '*', '*', '*', ' ', '*', '*' },
{'*', '*', '*', ' ', '*', '*', '*', ' ', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' }
};
Here is an example display. The entrance is on the upper left and the exit is on the lower right:
**********
*
** *** * *
** *******
* **
******* **
*** *** **
*
**********
**********
In homework 2 we will add a robot and, using random numbers, have it find a path out of the
maze.
OPTIONAL
Store your maze in a text file, and read it in rather than initializing it in your code.
Explanation / Answer
#include<iostream>
using namespace std;
int main(){
char maze[10][10] =
{ {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{'*', '*', ' ', '*', '*', '*', ' ', '*', '*', ' ' },
{'*', '*', ' ', '*', '*', '*', '*', '*', '*', '*' },
{'*', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', ' ' },
{'*', '*', '*', '*', '*', '*', '*', ' ', '*', '*' },
{'*', '*', '*', ' ', '*', '*', '*', ' ', '*', '*' },
{'*', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' },
{'*', '*', '*', '*', '*', '*', '*', '*', '*', '*' }
};
for(int i = 0; i<10; i++){
for (int j = 0; j<10; j++){
cout << maze[i][j] ;
}
cout << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.