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?
#include <iostream>
usingnamespace 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 = newint *[N];
for (int i = 0; i<N; i++)
arr[i] = newint[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;
}
}