This is the code that is suppose to compute the class's average and standard diviation from a file which contains a collection of student ids and corresponding scores from my computer class and assign each student a letter grade. the class can have no less than 7 students and no more than 25 student
I need help with aeraging the grades
Code:#include <fstream.h> #include <iostream.h> #include <stdlib.h> #include <iomanip.h> struct mike { int id; float average = 0; char lettergrade[1]; int numgrade; int total = 0; }hope; void main() { ifstream MyData; MyData.open("getdata.dat"); ofstream PutData; PutData.open("putdata"); if(MyData.fail()) { cout << "\n\nFile not successfully opened\n\n"; } cout << "\n\nFile Successfully opened\n\n"; int i=0; do{ MyData >> hope.id >> hope.numgrade; cout << hope.id << "\t" << hope.numgrade << "\t" << hope.lettergrade << "\t" << hope.average; hope.total = hope.total + hope.numgrade; hope.average = hope.average/hope.total; if (hope.numgrade >= 90) strcpy(hope.lettergrade,"A"); else if (hope.numgrade >= 80) strcpy(hope.lettergrade,"B"); else if (hope.numgrade >= 70) strcpy(hope.lettergrade,"C"); else if (hope.numgrade >= 60) strcpy(hope.lettergrade,"D"); else strcpy(hope.lettergrade,"F"); PutData << "\n\n\n Class Grades"; PutData << "\n"; PutData << " Student ID: " << hope.id << endl; PutData << " Student Numbergrade: " << hope.numgrade << endl; PutData << " Student Lettergrade: " << hope.lettergrade << endl; PutData << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2); PutData << " Class Average: " << hope.average << endl; }while(i>7 && i<25); MyData.close(); PutData.close(); }



LinkBack URL
About LinkBacks


