title: Calculating average, min, max of a 2d array
body: <p>I'm supposed to write a program to read and fill an array with 5 student IDs and their grades then print the average, min and max grades with the IDs of the students, an example could be:
  Student 1: 111 56
  Student 2: 222 98
  Student 3: 333 90
  Student 4: 444 68
  Student 5: 555 88
  Average: 80
  Rank#1: 222 98
  Rank#5: 111 56
  My program is giving me messed up values (Average is 328.4, rank#1: 444 555, rank#5: 555 88) along with a debug error (Run-Time Check Failure #2 - Stack around the variable 'a' was corrupter), here it is</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  void avg(double a[4][1]);
  void minMax(double a[4][1]);
  void main () {
      double a[4][1];
      cout &lt;&lt; "Enter 5 students' IDs and marks:\n";
      int studentNum = 1;
      for (int r=0; r&lt;5; r++) {
          cout &lt;&lt; "Student" &lt;&lt; studentNum &lt;&lt; ": ";
          studentNum++;
          for (int c=0; c&lt;2; c++) 
              cin &gt;&gt; a[r][c]; }
      avg(a);
      minMax(a); }
  void avg(double a[4][1]){
      double sum=0.0;
      for (int r=0; r&lt;5; r++) {
          for (int c=1; c&lt;2; c++) // does not include the ID column
              sum = sum + a[r][c]; }
      double avg = sum/5; // number of students = 5
      cout &lt;&lt; "Average: " &lt;&lt; avg &lt;&lt; endl; } 
  void minMax (double a[4][1]) {
      double min = a[0][1];
      double max = a[0][1];
      int minID = a[0][0];
      int maxID = a[0][0];
      for (int r=0; r&lt;5; r++) {
          for (int c=1; c&lt;2; c++) {
              if (a[r][c] &lt; min){
                  min = a[r][c];
                  minID = a[r][0]; }
              if (a[r][c] &gt; max){
                  max = a[r][c];
                  maxID = a[r][0]; } } } 
      cout &lt;&lt; "Rank#1: " &lt;&lt; maxID &lt;&lt; " " &lt;&lt; max &lt;&lt; endl;
      cout &lt;&lt; "Rank#5: " &lt;&lt; minID &lt;&lt; " " &lt;&lt; min &lt;&lt; endl; }
  </code></pre>
  
  <p>Any help will be greatly appreciated, thank you so much!</p>