title: C++ - File I/O and Char arrays
body: <p>The following is the problem description:</p>
  
  <blockquote>
    <p>The history teacher at your school needs help in grading a True/False test.
    The students’ IDs and test answers are stored in a file. The first entry in the
    file contains answers to the test in the form:</p>
    
    <p>TFFTFFTTTTFFTFTFTFTT</p>
    
    <p>Every other entry in the file is the student ID, followed by a blank, followed
    by the student’s responses. For example, the entry:</p>
    
    <p>ABC54301 TFTFTFTT TFTFTFFTTFT</p>
    
    <p>indicates that the student ID is ABC54301 and the answer to question 1 is
    True, the answer to question 2 is False, and so on. This student did not
    answer question 9. The exam has 20 questions, and the class has more than
    150 students. Each correct answer is awarded two points, each wrong answer
    gets one point deducted, and no answer gets zero points. Write a program
    that processes the test data. The output should be the student’s ID, followed
    by the answers, followed by the test score, followed by the test grade.
    Assume the following grade scale: 90%–100%, A; 80%–89.99%, B;
    70%–79.99%, C; 60%–69.99%, D; and 0%–59.99%, F.</p>
  </blockquote>
  
  <p>This is the program I have made:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
  //declaring variables
  ifstream file("grading.txt");
  char key[21];
  char id[9];
  char student[21];
  int score = 0, i;
  
  //initializing arrays
  for(i=0; i&lt;21; i++)
  {
      key[i]=0;
      student[i]=0;
  }
  for(i=0; i&lt;9; i++)
      id[i]=0;
  
  //processing the key
  file &gt;&gt; key;
  file.ignore(100, "\n");
  
  //processing student grades
  while(file.good())
  {
  
      file &gt;&gt; id;
      file.ignore();
      getline(file, student);
      file.ignore(100, "\n");
  
      //comparing key and student answer
      for(i=0; i&lt;21; i++)
      {
          if(strcmp(student[i], key[i])
              score += 2;
          else
              score -= 1;
      }
  
      //outputing student id, score and grade
      cout &lt;&lt; "Student ID: " &lt;&lt; id;
      cout &lt;&lt; "Score: " &lt;&lt; score;
      score = (score/(40))*100;
      if(score &gt;= 90 &amp;&amp; score &lt;= 100)
          cout &lt;&lt; "Grade: A" &lt;&lt; endl &lt;&lt; endl;
      else if(score &gt;= 80 &amp;&amp; score &lt;= 89.99)
          cout &lt;&lt; "Grade: B" &lt;&lt; endl &lt;&lt; endl;
      else if(score &gt;= 70 &amp;&amp; score &lt;= 79.99)
          cout &lt;&lt; "Grade: C" &lt;&lt; endl &lt;&lt; endl;
      else if(score &gt;= 60 &amp;&amp; score &lt;= 69.99)
          cout &lt;&lt; "Grade: D" &lt;&lt; endl &lt;&lt; endl;
      else if(score &gt;= 0 &amp;&amp; score &lt;= 59.99)
          cout &lt;&lt; "Grade: F" &lt;&lt; endl &lt;&lt; endl;
      else
          cout &lt;&lt; "Invalid percentage" &lt;&lt; endl;
  }
  
  //closing file
  file.close();
  
  return 0;
  }
  </code></pre>
  
  <p>I seem to be getting the following compilation errors: <a href="http://pastebin.com/r0Y1xX8M" rel="nofollow">http://pastebin.com/r0Y1xX8M</a> (couldn't edit the errors properly on here, sorry)</p>
  
  <p>Help would be appreciated with the compile errors, and any other suggestions as to how to solve this.</p>