title: File inputs in loops
body: <p>I was asked to obtain text and numbers from a .txt file to a C++ program.
  What I don't know is the number of students I will be sorting their grades out so I use a while loop with the condition of !fin.eof()
  Code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
  ifstream fin;
  fin.open("grades.txt");
  cout &lt;&lt; "Name\t\t\t" &lt;&lt; "Midterm\t" &lt;&lt; "HMAvg\t" &lt;&lt; "Final\t" &lt;&lt; "Average\t" &lt;&lt; "Grade" &lt;&lt; endl;
  
  while(!fin.eof())
  {
      string name;
      double mdtrm, final, hw, shw=0, ahw=0, avg;
      char grade;
  
      getline(fin, name);
  
      fin &gt;&gt; mdtrm;
      fin &gt;&gt; final;
  
      for(int i=0; i&lt;5; i++)
      {
          fin &gt;&gt; hw;
          shw = shw+hw;
      }
  
      ahw = shw/5;
      avg = ((mdtrm*0.3)+(final*0.4)+(ahw*0.3));
  
      if(avg&gt;=90 &amp;&amp; avg&lt;=100)
          grade = 'A';
      else if(avg&gt;=80 &amp;&amp; avg&lt;90)
          grade = 'B';
      else if(avg&gt;=70 &amp;&amp; avg&lt;80)
          grade = 'C';
      else
          grade = 'F';
  
      cout &lt;&lt; name &lt;&lt; "\t" &lt;&lt; mdtrm &lt;&lt; "\t" &lt;&lt; ahw &lt;&lt; "\t" &lt;&lt; final &lt;&lt; "\t" &lt;&lt;  avg &lt;&lt; "\t" &lt;&lt; grade &lt;&lt; endl;
  }
  
  fin.close();
  
  system("pause");
  
  return 0;
  }
  </code></pre>
  
  <p>It infinitely loops. I made sure the .txt file is ok
  What's wrong with my code ?</p>