I am writing a program that grabs information from a .dat file. I have the code all structured up, but I get these 2 errors that does not make any sense to me on how to fix the program. Am I missing something?

When you get this program to compile, you will find that you also have issues re reading of the data and of calculating total gross. Using the debugger should help you find the problem re calulation.

With regard to the issue reading the data. When you find eof(), the file is put into a 'fail' state which means that no further data can be read until this state is cleared using the .clear() function. There is also no need to close and re-open the file. Just position the file to the beginning using .seekg() after clearing the error.

You are using .eof() to determine when the end of file has been reached. Another way of doing this is

Code:

while (fin >> d >> n >> gp) count++;

as extracting from a file causes a fail when data cannot be read which means that the extraction returns a 0 as opposed to a reference to the stream if the extraction worked ok.

Also note that the format of the data you are extracting from the file does not match the .dat file contents shown in post #1.