I have my coding idea laid out, but I think there is an easier way, plus I can't really get it to work, because I don't know how to accommodate for duplicated values.
Here is my data:
Enter name of file
students
StudentID LastName FirstName Q1 Q2 Q3 Mid Q4 Q5 Q6 Final Avg. Grade
--------------------------------------------------------------------------------------------
45256 Rodrigues Joana 58 75 58 61 59 75 63 92 6969
37915 Wright Michelle 98 83 56 62 63 90 57 67 7070
81984 Williams Jenny 55 67 54 63 89 84 93 75 7575
73984 Phaneuf Lesley 78 85 57 51 68 94 51 83 6969
80886 Laflamme Nicole 76 51 71 94 69 78 87 91 8080
39473 Kenyon Patricia 65 54 90 68 94 70 95 97 8282
Press any key to continue . . .
but, as you can see my avg is doubled somehow, and I would actually like it to be a double so that I can have that decimal point....here is my code
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60],
int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60],
int Q5[60], int Q6[60], int Final[60], int i);
void main()
{
ifstream students;
ofstream out;
string fname[60];
string studentid[60];
string lname[60];
string id[60];
int Q1[60];
int Q2[60];
int Q3[60];
int MidTerm[60];
int Q4[60];
int Q5[60];
int Q6[60];
int Final[60];
string file;
int i;
cout << "Enter name of file" << endl;
cin >> file; file += ".txt";
students.open(file.c_str());
if(students)
{
out.open("CompleteReport.txt");
out << "Student Grade Report:" << endl;
cout << fixed << setprecision(1);
out << fixed << setprecision(1);
cout << endl
<< "StudentID LastName FirstName Q1 Q2 Q3 Mid Q4 Q5 Q6 Final Avg. Grade"
<< endl;
cout << "--------------------------------------------------------------------------------------------"
<<endl;
out << "StudentID LastName FirstName Q1 Q2 Q3 Mid Q4 Q5 Q6 Final Avg. Grade"
<< endl;
out << "--------------------------------------------------------------------------------------------"
<<endl;
for (i = 0; i < 6; ++i )
{
if ( students >> studentid[i] >> fname[i] >> lname[i] >> Q1[i] >> Q2[i] >> Q3[i] >> MidTerm[i]
>> Q4[i] >> Q5[i] >> Q6[i] >> Final[i])
{
cout << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(12) << lname[i] << setw(7)
<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i];
CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i);
out << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(8) << lname[i] << setw(7)
<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i];
CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i);
cout << endl;
}
else
{
break;
}
}
students.close();
}
}
//double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60],
// int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60],
// int Q6[60], int Final[60],int i)
//{
// return ((Q1[i] + Q2[i] + Q3[i] + (MidTerm[i]*2) + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8);
//}
void CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60],
int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60],
int Q6[60], int Final[60],int i)
{
if ((Q1[i] < Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]) &&
(Q1[i] != Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i]))
cout << (Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 7;
else if (Q2[i] < Q1[i] && Q3[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i])
cout << (Q1[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 7;
else if (Q3[i] < Q1[i] && Q2[i] && MidTerm[i] && Q4[i] && Q5[i] && Q6[i] && Final[i])
cout << (Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 7;
else if (Q4[i] < Q2[i] && Q3[i] && MidTerm[i] && Q1[i] && Q5[i] && Q6[i] && Final[i])
cout << (Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 7;
else if (Q5[i] < Q2[i] && Q3[i] && MidTerm[i] && Q4[i] && Q1[i] && Q6[i] && Final[i])
cout << (Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q1[i] + Q6[i] + Final[i]) / 7;
}
//CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final, i)
How can I fix this....and possibly make the function a little easier to follow?