I am trying to create a Magic Square program based on a text file input. I'm getting stuck on the arrays. I need to get the size of the array from 'n' number then store the values of the rows and columns in 2d array. So here's an example from the text file:
3
4 9 2
3 5 7
8 1 6
3 would be the n, then I'd need a 2d array to store the n x n information. Here's what I coded:
int main() {
int n;
ifstream inFile;
inFile.open("input.txt");
inFile >> n;
int square[n][n];
readSquare(n, square);
}
void readSquare(int n, int square[][]) {
ifstream inFile("input.txt");
for (int r = 0; r < n; r++)
{
for (int c = 0; c < n; c++)
{
inFile >> square[r][c];
cout << square[r][c];
system("pause");
}
}
}