--------------- ENGLISH CHINESE HISTORY SCIENCE
TEE KEE SONG 99 56 22 79
JOHN STONE 88 22 99 99
Above is the format of my text file.
I want to use the marks to calculate the average marks of the students.
The following is my code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream readfile;
readfile.open("students.txt");
string line;
getline (readfile,line);
double sub1,sub2,sub3,sub4;
string name;
while(!readfile.eof())
{
getline(readfile,line);
readfile>>name>>sub1>>sub2>>sub3>>sub4;
}
cout<< name<<sub1<<sub2<<sub3<<sub4;
readfile.close();
return 0;
}
How can I modify it to get it works?
Last edited on