title: Run-Time Check Failure #2 - Stack around the variable 'projectAverage' was corrupted
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main(){
      double hw = 0, hwTotal = 0, hwAverage[3], id[3], project = 0, projTotal = 0, projectAverage[3], hwProj, finalExam[3], total[3];
      int i = 0, j = 0, k = 0;
  
      for (j = 0; j &lt; 3; j++){
          cout &lt;&lt; "Input student ID: ";
          cin &gt;&gt; id[i];
          for (i = 0; i &lt; 4; i++){
              cout &lt;&lt; "Input homework assignment grade: ";
              cin &gt;&gt; hw;
  
              hwTotal = hwTotal + hw;
          }
  
          hwAverage[j] = hwTotal / 4;
  
          for (i = 0; i &lt; 2; i++){
              cout &lt;&lt; "Input project grade: ";
              cin &gt;&gt; project;
  
              projTotal = projTotal + project;
          }
  
          projectAverage[j] = projTotal / 2;
  
          hwProj = (hwAverage[j] + projectAverage[j]) / 2;
  
          cout &lt;&lt; "Input final exam grade: ";
          cin &gt;&gt; finalExam[j];
  
          total[j] = (finalExam[j] + hwProj) / 2;
      }
  
      cout &lt;&lt; endl;
  
      for (k = 0; k &lt; 3; k++){
          cout &lt;&lt; "Student ID: " &lt;&lt; id[k] &lt;&lt; endl;
          cout &lt;&lt; "Homework Average: " &lt;&lt; hwAverage[k] &lt;&lt; endl;
          cout &lt;&lt; "Project Average: " &lt;&lt; projectAverage[k] &lt;&lt; endl;
          cout &lt;&lt; "Final exam grade: " &lt;&lt; finalExam[k] &lt;&lt; endl;
          cout &lt;&lt; "Final average: " &lt;&lt; total[k] &lt;&lt; endl;
  
          cout &lt;&lt; endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>For some reason, when I run this code, my output looks like this:</p>
  
  <blockquote>
    <ul>
    <li>Input student ID: 123</li>
    <li>Input homework assignment grade: 100</li>
    <li>Input homework assignment grade: 100</li>
    <li>Input homework assignment grade: 100</li>
    <li>Input homework assignment grade: 100</li>
    <li>Input project grade: 100</li>
    <li>Input project grade: 100</li>
    <li>Input final exam grade: 100</li>
    <li>Input student ID: 12</li>
    <li>Input homework assignment grade: 40</li>
    <li>Input homework assignment grade: 40</li>
    <li>Input homework assignment grade: 40</li>
    <li>Input homework assignment grade: 40</li>
    <li>Input project grade: 40</li>
    <li>Input project grade: 40</li>
    <li>Input final exam grade: 40</li>
    <li>Input student ID: 1</li>
    <li>Input homework assignment grade: 20</li>
    <li>Input homework assignment grade: 20</li>
    <li>Input homework assignment grade: 20</li>
    <li>Input homework assignment grade: 20</li>
    <li>Input project grade: 20</li>
    <li>Input project grade: 20</li>
    <li><p>Input final exam grade: 20</p></li>
    <li><p>Student ID: 123</p></li>
    <li>Homework Average: 100</li>
    <li>Project Average: 100</li>
    <li>Final exam grade: 100</li>
    <li><p>Final average: 100</p></li>
    <li><p>Student ID: -9.25596e+061</p></li>
    <li>Homework Average: 140</li>
    <li>Project Average: 140</li>
    <li>Final exam grade: 40</li>
    <li><p>Final average: 90</p></li>
    <li><p>Student ID: 1</p></li>
    <li>Homework Average: 160</li>
    <li>Project Average: 160</li>
    <li>Final exam grade: 20</li>
    <li><p>Final average: 90</p></li>
    <li><p>Press any key to continue . . .</p></li>
    </ul>
  </blockquote>
  
  <p>And I get a stack overflow error. I'm pretty new to C++, and I was making a program that would ask the user for 10 homework assignment grades, 2 project grades, and a final exam grade from 10 students (the numbers in my program are lower so that I could test it easier). I was going to average the homework grades and the project grades separately, then average those averages, then average that average with the final exam grade for a total average (sorry about all the averages), but it doesn't seem to be working and I have no idea why. Like I said, I'm pretty new to C++, and even newer to arrays, so do you think that any of you can give me some insight as to where I went wrong? Thank you so much!</p>