Ok this program that i am writing is a pain. I amsupposed to create a program that will print out a students ID number along with their grades in each class. Now there is a file with all class names like this one: (classes.dat)
CSC1
CSC2
CSC46
CSC151
MTH121
PHY50
CHN1
and as an example here is what is in one of the class files; (CSC1.dat):
11234 A-
12547 B
16753 B+
21886 C
48815 C+
i've got a program but it has some problems printing out the right things. Here it is but i'm pretty sure that its the function that causes the error.
Thanks for your time.Code:#include <fstream> #include <iostream> #include <cstdlib> #include <string> #include <sstream> using namespace std; void read_data(string ID,istream& in); int main() { cout<<"Welcome User to the Imaginary College Transcript Search & Printout"<<endl; cout<<endl; bool more; while(more) { string ID; string answer; fstream text; cout<<"Please Enter the ID number of the Student:"<<"\n"; cin>>ID; text.open("classes.dat"); if(text.fail()) { cout<<"You Are at the Wrong School.\n"; exit(1); } read_data(ID,text); text.close(); cout<<"Do You Wish to Print Out Another Transcript ? (y/n)"<<endl; cin>>answer; if(answer == "y") { continue; } else if (answer == "n") { more = false; } else { cout<<"You Obviously Don't Go to This College." <<endl; cout<<"Attempt Answering Properly Next Time."<<endl; exit(3); } } return 0; } void read_data(string ID,istream& in) { fstream data; char class_name[10]; int counter = 0; string ident; char mark; while (counter<7) { for (int j=0;j<1;j++) { in>>class_name; data.open("class_name.dat"); for (int i=0;i<2;i++) { if (i==0) { data>>ident; } else { data>>mark; } } if(ident == ID) { cout<<"Student ID "<<ident<<endl; cout<<class_name<<" "<<mark<<endl; } } data.close(); counter++; } }



LinkBack URL
About LinkBacks


