I want to make aprogram to read a file including the marks of student where each line includes the student name ,his bench number and mark .. i want to use this program to write that in a nother file which will include the same things included in the input file and also to calculate the average of the marks of the student and write it in the output file
i wrote the following and it doesnt work can you tell me what are the problems with my code
so any one can tell me what are the errors and also if there is another method to do thatCode:#include<iostream> #include<cstdlib> #include<fstream> using namespace std; struct student { char name[]; // for the name of the student int BN; // for the bench number int mark; //for the mark of the student int main() { student m; double sum ,av; // sum is the sum of the marks of students and av is their average int i=0; //counting the nuber of students sum =0; ifstream fin; ofstream fout; fin.open("E://marks.txt"); if (fin.fail()) { cout<<"Can not open file\n"; exit(1); } fout.open("E://results.txt") fin>>m.name; while(!fin.eof()) { fout<<m.name; fout<<" "; //space fin>>m.BN; fout<<m.BN; fout<<" "; fin>>m.mark; sum+=m.mark; fout<<m.mark; fout<<endl; i++; fin>>m.name; } av=sum/i; fout<<" the average of the students is :"<<av <<endl; fin.close(); fout.close(); return 0; }
thanks in advance