Reading a text file using I/O -- Line by Line

Hello,

I need help ASAP figuring out how to fix my problem with reading a text file, line by line, and stopping on each line, ended by a -1 (sentinel-control)

Here are the conditions: The text file is a list of grades for a class. Each line indicates a separate grade (lab, exam, homework, etc.) Each line is ended by -1, which tells the program to stop reading that line. I need to read the text file, line by line, WITHOUT USING A STRING, ending at the -1. I can read the first line, but how do I read the next line, skipping the first?

Example:

#include<iostream>
#include<fstream>

using namespace std;

int main(){

int labcount = 0, quizcount = 0, hwcount = 0, examcount = 0, assigncount = 0;
double lab, quiz, homework, exam, assignment;
double weightedtotal = 0;

ifstream inFile;
ofstream outFile;

inFile.open("grades.txt");
outFile.open("grade_report.txt");


while(??line1??){
inFile>>grades;
while (grades != -1){
lab = grades + lab;
labcount++;
}
lab = lab/labcount;
outFile << "Your lab average is: "<<lab<<endl;

weightedtotal = (lab * (0.15)) + weightedtotal;
}
return 0;
}


the program is meant to read several lines of text, for different grades....

the text file would look something like this:

50 100 65 89 95 -1
60 75 -1

etc...

HELP!
Topic archived. No new replies allowed.