2d array

For school we need to write an 80x20 2d array that stores six pathways, each of which is a straight line between two randomly selected points on the perimeter of the array. My problem is that I don't know how to make it so there will be six random pathways( or lines I guess) on the 2d array, just how to make random lines on it. Can someone give me a hand, please?

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
const int rows = 80; //declares the amount of rows in the 2d array
const int cols = 20; //declares the amount of columns in the 2d array
char terminal[rows][cols];

fill_n(&terminal[0][0], 100, '-');
fill_n(&terminal[0][0] + 100, rows*cols - 100, ' ');
random_shuffle(&terminal[0][0], &terminal[0][0] + rows*cols);

for(int r = 0; r < rows; ++r)
{
for(int c = 0; c < cols; ++c)
cout << terminal[r][c];
cout << " ";
}
return 0;
}
Last edited on
Not sure what you mean by lines in the array
are you trying to do something like

111111
111111
111111
because that would be like 80, 6 and not 80x20
I mean like connecting points on the perimeter on the array to form a line, inside it would be just spaces, like this:
-----
| |
| |
| |
-----
But there would six of these, one for each path, so the whole array wouldn't have a border around it.
Last edited on
Topic archived. No new replies allowed.