I'm Trying to read from a file- IStudent.dat, and i keep getting the wrong output- "invalid grade" ..what is wrong with my program?
the data file is at the bottom after the code.
Data FileCode:#include<iomanip.h> #include<fstream.h> #include<stdlib.h> #define Max 8 main() { int ID[Max], Test[Max], C; char Grade; ifstream IStudent("IStudent.dat"); for(C=0;C<Max;C++) { IStudent>>Test[C]; if(Test[C]<100 && Test[C]>90) {Grade='A';} else if(Test[C]<89 && Test[C]>80) {Grade='B';} else if(Test[C]<79 && Test[C]>70) {Grade='C';} else if(Test[C]<69 && Test[C]>60) {Grade='D';} else if(Test[C]<59 && Test[C]>0) {Grade='F';} else {cout<<"Invalid Grade"<<endl;} } system("PAUSE"); return 0; }
Code:8 Records in File ID Test Score ------------------------------------------------------- 123 97 234 54 345 77 456 65 567 87 678 69 789 84 890 76



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.