title: ask the user to enter the studentID. Then you will open the text file and search for this ID. (C++)
body: <p>Struggling really hard with this, I need to enter an ID number thats in a text file and output the associated grades that are on the same line of the text file</p>
  
  <p>This is the code I have, it prints the correct average but it prints the test scores of the next ID numeber</p>
  
  <pre><code>int searchID;
  int studentID;
  bool found = false;
  
  double exam_1;
  double exam_2;
  double exam_3;
  double average = 0;
  
  cout &lt;&lt; "Enter student ID to search in file " &lt;&lt;
      fileName &lt;&lt; " : ";
  //read searchID value
  cin &gt;&gt; searchID;
  
  //read data from file until the search id is found
  while (fin &gt;&gt; studentID &gt;&gt; exam_1 &gt;&gt; exam_2
      &gt;&gt; exam_3 &amp;&amp; !found)
  {
      if (searchID == studentID)
      {
          average = (exam_1 + exam_2 + exam_3) / 3.0;
          found = true;
      }
  }
  //close the file stream,fin
  fin.close();
  //check if search id is found
  if (found)
  {
      cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; "Exam 1" &lt;&lt; setw(10) &lt;&lt; exam_1 &lt;&lt; endl;
      cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; "Exam 2" &lt;&lt; setw(10) &lt;&lt; exam_2 &lt;&lt; endl;
      cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; "Exam 3" &lt;&lt; setw(10) &lt;&lt; exam_3 &lt;&lt; endl;
      cout &lt;&lt; fixed &lt;&lt; setprecision(2)
          &lt;&lt; "Average : " &lt;&lt; average &lt;&lt; endl;
  }
  else
      cout &lt;&lt; searchID &lt;&lt; " student id is not found." &lt;&lt; endl;
  
  system("pause");
  </code></pre>