I'm supposed to write a program that inputs various student id numbers from a file, then takes the average of all their quiz scores and outputs their id numbers and avg quiz score. I was told to make a special case of the first record. But I am ridiculously confused. My awful code is below. Its not reading in anything from the file I've inputted
@gary special case of the first record what is this case u dint tell us.?
Plus i cant see where you checked to confirm if the file successfully openedif(fin.fail ()/ if(! fin) , how are your records arranged in that file.
doc file (I presume it is Microsoft Word file) are not text file. It is complex binary format which cannot be simply read as text. If you want to use text streams, you should save your file in plain text format.
Also:
1) You are looping on .eof(). Do not do that. Loop on input operation instead.
2) You do not read anything from file after first read. That means if your file contain some information when loop is executed, your program will hang.
1. I guess it's better to pass the filename to the steam constructor. fstream fin ("file.txt");
I prefer this. the file gets opened and closed after use.
2. It is always better to check if the file opened just fine you can use what
I gave above.
3. prefer not to use eof () @minnippa already tould you can use while (fin).
4 . I can't see where your reading the file in your loop, well you can use getline and read it
into a stringstream object or a std::string then parse it to obtain your values.
5. As i see your record you might want too hold the id no get the score average till the id no changes.
hope that helps.