Calling function in main()

In this code I've written two functions, which I both call from main(). However, I'm stuck when calling playGame() on line 16. How do I pass the pointer of the array if it isn't defined or declared in main?

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
#include <iostream>
using namespace std;

int ** createField(int N);
int playGame(int ** arr, int N);

int main()
{
	int N;

	cout << "Enter the number of Redshirts: " << endl;
	cin >> N;

	**createField(N);

	playGame(**arr, N);
}

int ** createField(int N)
{
	int ** arr = new int *[N];
	for (int i = 0; i<N; i++)
		arr[i] = new int[N];

	for (int i = 1; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			arr[i][j] = 0;
			arr[1][j] = 1;
		}
	}

	return arr;
}

int playGame(int ** arr, int N)
{
	int x, y;
	cout << "Enter the coordinates of the " << N << " shots: " << endl;

	for (int i = 0; i < N; i++)
	{
		cin >> x >> y;
		if (arr[x][y] = 1 || arr[x + 1][y])
			cout << "Your hit a Redskin" << endl;
	}
}
Is it really necessary to use use dynamic arrays?
It would be easier with vectors.
How do I pass the pointer of the array if it isn't defined or declared in main?

Then declare a pointer in main().

1
2
3
    int ** arr = createField(N);

    playGame(arr, N);
Topic archived. No new replies allowed.