HI all I am brand new to C++.(like chaper 2 in D&D)..and my new assignment is driving me insane!
I am doing external data formatting student IDs and 4 grades into a table of ID#s...GPA...and special notes for
honors >= GPA 3.5 and warnings GPA <=1.5.
I've got that while loop down with an if/else if nested...
and it works well.
The thing is the headers STUDENT ID GPA
SPECIAL NOTATION
I have them before and out of the while loop and they come up great EXCEPT when I try to say
"if there's an ID number in the infile print the header and go on to the data, but if the infile is empty print <NO DATA>"
when I add that if/else statement before the while statement, it does print out NO DATA for the empty file but
eliminates the first student in the list
when i format the other files...(file3).
I hope I am being clear enoguh.
the 3 external data files are as follows:
__________________________________________________ __________________________________________________ _______________________________
1.
1022 2.0 2.0 2.0 4.0
1319 4.0 0.0 3.6 3.7
1191 3.0 0.0 1.5 1.5
1333 3.6 4.0 2.7 3.2
1032 2.2 3.7 2.6 2.8
1115 1.0 0.0 2.0 1.3
1234 1.0 1.0 1.0 1.0
1551 4.0 4.0 4.0 4.0
1789 4.0 3.1 3.0 2.7
1729 0.0 2.3 2.4 0.0
2.
//empty file
3.
1022 2.0 2.0 2.0 4.0
(The first number is the student ID and the next 4 their grades)
__________________________________________________ __________________________________________________ ______________________________________
the code that I am using that messes the output is in /* */...
without it I can print out my output correctly but cannot get a NO DATA statement for the second empty external file.
the output (which i am doing to the screen not a file so I can check it ...is:Code:#include<iostream> #include <iomanip> #include<fstream> #include<stdlib> using namespace.std int main() { cout << setprecision(3); cout << setiosflags(ios::fixed | ios::showpoint); int IDnum; double gr1, gr2, gr3, gr4; double average; double c1av; double c2av; double c3av; double c4av; ifstream infile("A:\\IF1.txt"); if (! infile) { cerr << "Cannot open input file" << endl; exit(1); } ofstream outfile("A:\\0F1.txt"); if (! outfile) { cerr << "Cannot open output file" << endl; exit(1); } cout << "\t\t\n\n"; /* infile >> IDnum >> gr1 >> gr2 >> gr3 >> gr4; if (IDnum > 0) cout<<setw(10)<<"\t\t\tSTUDENT"<<setw(10)<<"GPA"<<setw(20)<<"SPECIAL NOTE"<<endl; else if (IDnum <=0) cout<<setw(20)<<"\t\t\t<NO DATA"<<endl; */ cout << "\t\t\n\n"; while(infile >> IDnum >> gr1 >> gr2 >> gr3 >> gr4) { average =(gr1+gr2+gr3+gr4)/4; if (average <= 1.5) cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << "WARNING" << endl; else if (average >= 3.5) cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << "HONORS" << endl; else cout << setw(10) << "\t\t\t" << IDnum << setw(15) << average << setw(15) << endl; } cout << "\t\t\n\n\n"; infile.close(); outfile.close(); return 0; }
(it eliminates the first student)??
so, I am figuring it is because of the aqua code.
I really need some help here, I'm probably 16 hours deep into this and no closer to an answer than at the beginning!!!
2.
I need to also list the average for each grade (Ie: gr1, gr2 etc.)
would that loop also be included in the big while loop?
I am having trouble changing the names of the courses:
like course 1 average:
course 2 average:
etc....
I hope someone can please lend me a hand, i am so frustrated with this!
any guidance would be MOST appreciated..
scuba22
Michele
[code][/code]tagged by Salem



LinkBack URL
About LinkBacks


