 <p>You never check for 'eof' in your read loop in readInput(). This means you have garbage values (perhaps 0) for these lines after you hit eof:</p> <pre><code> inputFile &gt;&gt; data[i].name; inputFile &gt;&gt; data[i].idNum; inputFile &gt;&gt; data[i].testNum; </code></pre> <p>Then what do you suppose is going to happen here, if data[i].testNum is zero?</p> <pre><code> data[i].average = total / data[i].testNum; </code></pre> <p>You might consider checking <code>inputFile.good()</code> before each read from the stream, and handle it appropriately when it returns false.</p>