How to print a 2D array in C++?
<p>I am not sure how to print this 2D array. I am getting consistent errors in Visual Studio 2013. Every time I try to run it, it breaks and sometimes stops responding. If you see any other errors please let me know. Thank you for any help.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
using namespace std;

const int NUM_STUDENTS = 12;    // Number of students
const int NUM_QTRS = 4;         // Number of quarters

bool fillArr(double gpa[][NUM_QTRS]);
void averaging(double gpa[][NUM_QTRS], double avg[][12]);
void print(double avg[][12]);

int main()
{
double gpa[NUM_STUDENTS][NUM_QTRS]; // Array for 12 students, each with 4 quarters      
// define a 2D array called avg, which is 2 rows x 12 columns 
double avg[2][12];

// read from file and fill array with students gpas
if (!fillArr(gpa))
    return 1;

// Calculate average gpa for each student and store the student ID and average gpa of each student
averaging(gpa, avg);

// print the student ID and average gpa
print(avg);

// search for a student by ID
//search(avg);

// sort students by GPA
//sort(avg);
//print(avg);

return 0;
}

///// fill in the function definition below each description

// fillArr: read in from the file gpa.txt to fill the gpa array
bool fillArr(double gpa[][NUM_QTRS])
{
// open file
ifstream inFile;
inFile.open("gpa.txt");
if (!inFile)
{
    cout &lt;&lt; "Error opening gpa.txt/n";
    return false;
}

// read data into gpa array
for (int row = 0; row &lt; NUM_STUDENTS; row++)
{
    for (int col = 0; col &lt; NUM_QTRS; col++)
    {
        inFile &gt;&gt; gpa[row][col];
    }
}
inFile.close();
return true;
}

// averaging: calculate and store the ID and average gpa of each student in avg array
void averaging(double gpa[][NUM_QTRS], double avg[][12])
{
double total = 0;
for (int row = 0; row &lt; NUM_STUDENTS; row++)
{
    total = 0;
    for (int i = 0; i &lt; NUM_QTRS; i++)
    {
        total += gpa[row][i];
    }
    avg[row][12] = total / NUM_QTRS;
}
}

// print: print the student ID and average gpa of each student
void print(double avg[][12])
{
cout &lt;&lt; fixed &lt;&lt; setprecision(2);
cout &lt;&lt; "Student ID" &lt;&lt; "\tAverage GPA" &lt;&lt; endl;
for (int i = 0; i &lt; 2; i++)
{
    for (int j = 0; j &lt; 12; j++)
    {
        cout &lt;&lt; avg[i][j];
    }
}
}
</code></pre>