Hello all! Working on a project where I need to fill a file with numbers and use a getline to read those numbers line by line and then display the total, average, max, and min from each line. Everything's in place except my getline doesn't seem to be working as the output for the total, average, etc, is always 0. Any help at all is appreciated. Thanks!
The test at line 14 if(myfile.is_open()) is redundant, since the program would have already ended at line 12 if it was not.
At line 61, myfile.close(); just before the program ends is logically out of sequence. You need to close the output file before attempting to re-open it for input. (well, there may be exceptions, but let's keep things simple).
There is no check that the input file was opened successfully.
Using eof() in a loop condition is a no-no, don't do it or things will usually turn out badly. What you do need to do is try to read a line from the file, and only process that line if the read operation was successful. eof() before the read doesn't tell you that.
One more thing - you may not be familiar with this. To get the numbers contained within a line of text, the easiest way is to use a stringstream, and read integers from that as though it was a file.