Alright....this is a mess, but it works (compikes) correctly....how would I create a function (probably using "switch") to return a grade based on the averages found in CalculateAvg?
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
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);
double FindLargest(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);
char grade(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));
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];
int average;
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)
{
double average1, average1a, average1b, average1c, average1d;
double average2, average2a, average2b, average2c, average2d;
double average3, average3a, average3b, average3c, average3d;
double average4, average4a, average4b, average4c, average4d;
double average5, average5a, average5b, average5c, average5d;
double average6, average6a, average6b, average6c, average6d;
double largest1, largest2, largest3, largest4, largest5, largest6;
largest1 = (Q1[i] * 2);
largest2 = (Q2[i] * 2);
largest3 = (Q3[i] * 2);
largest4 = (Q4[i] * 2);
largest5 = (Q5[i] * 2);
largest6 = (Q6[i] * 2);
average1 = ((largest2) + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average1a = (Q2[i] + (largest3) + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average1b = (Q2[i] + Q3[i] + (MidTerm[i] * 2) + (largest4) + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average1c = (Q2[i] + Q3[i]+ (MidTerm[i] * 2) + Q4[i] + (largest5) + Q6[i] + (Final[i] * 3) )/ 12;
average1d = (Q2[i] + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + (largest6) + (Final[i] * 3) )/ 12;
average2 = ((largest1) + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average2a = (Q1[i] + (largest3) + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average2b = (Q1[i] + Q3[i] + (MidTerm[i] * 2) + (largest4) + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average2c = (Q1[i] + Q3[i] + (MidTerm[i] * 2) + Q4[i] + (largest5) + Q6[i] + (Final[i] * 3) )/ 12;
average2d = (Q1[i] + Q3[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + (largest6) + (Final[i] * 3) )/ 12;
average3 = ((largest1) + Q2[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average3a = (Q1[i] + (largest2) + (MidTerm[i] * 2) + Q4[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average3b = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + (largest4) + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average3c = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q4[i] + (largest5) + Q6[i] + (Final[i] * 3) )/ 12;
average3d = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q4[i] + Q5[i] + (largest6) + (Final[i] * 3) )/ 12;
average4 = ((largest1) + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average4a = (Q1[i] + (largest2) + (MidTerm[i] * 2) + Q3[i] + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average4b = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + (largest3) + Q5[i] + Q6[i] + (Final[i] * 3) )/ 12;
average4c = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + (largest5) + Q6[i] + (Final[i] * 3) )/ 12;
average4d = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q5[i] + (largest6) + (Final[i] * 3) )/ 12;
average5 = ((largest1) + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q6[i] + (Final[i] * 3) )/ 12;
average5a = (Q1[i] + (largest2) + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q6[i] + (Final[i] * 3) )/ 12;
average5b = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + (largest3) + Q4[i] + Q6[i] + (Final[i] * 3) )/ 12;
average5c = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + (largest4) + Q6[i] + (Final[i] * 3) )/ 12;
average5d = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + (largest6) + (Final[i] * 3) )/ 12;
average6 = ((largest1) + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q5[i] + (Final[i] * 3) )/ 12;
average6a = (Q1[i] + (largest2) + (MidTerm[i] * 2) + Q3[i] + Q4[i] + Q5[i] + (Final[i] * 3) )/ 12;
average6b = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + (largest3) + Q4[i] + Q5[i] + (Final[i] * 3) )/ 12;
average6c = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + (largest4) + Q5[i] + (Final[i] * 3) )/ 12;
average6d = (Q1[i] + Q2[i] + (MidTerm[i] * 2) + Q3[i] + Q4[i] + (largest5) + (Final[i] * 3) )/ 12;
if ((Q1[i] <= Q2[i] && Q1[i] <= Q3[i] && Q1[i] <= Q4[i] && Q1[i] <= Q5[i] && Q1[i] <= Q6[i]) &&
(Q2[i] >= Q1[i] && Q2[i] >= Q3[i] && Q2[i] >= Q4[i] && Q2[i] >= Q5[i] && Q2[i] >= Q6[i]))
return average1;
else if ((Q1[i] <= Q2[i] && Q1[i] <= Q3[i] && Q1[i] <= Q4[i] && Q1[i] <= Q5[i] && Q1[i] <= Q6[i]) &&
(Q3[i] >= Q2[i] && Q3[i] >= Q1[i] && Q3[i] >= Q4[i] && Q3[i] >= Q5[i] && Q3[i] >= Q6[i]))
return average1a;
else if ((Q1[i] <= Q2[i] && Q1[i] <= Q3[i] && Q1[i] <= Q4[i] && Q1[i] <= Q5[i] && Q1[i] <= Q6[i]) &&
(Q4[i] >= Q1[i] && Q4[i] >= Q2[i] && Q4[i] >= Q3[i] && Q4[i] >= Q5[i] && Q4[i] >= Q6[i]))
return average1b;
else if ((Q1[i] <= Q2[i] && Q1[i] <= Q3[i] && Q1[i] <= Q4[i] && Q1[i] <= Q5[i] && Q1[i] <= Q6[i]) &&
(Q5[i] >= Q1[i] && Q5[i] >= Q2[i] && Q5[i] >= Q3[i] && Q5[i] >= Q4[i] && Q5[i] >= Q6[i]))
return average1c;
else if ((Q1[i] <= Q2[i] && Q1[i] <= Q3[i] && Q1[i] <= Q4[i] && Q1[i] <= Q5[i] && Q1[i] <= Q6[i]) &&
(Q6[i] >= Q1[i] && Q6[i] >= Q2[i] && Q6[i] >= Q3[i] && Q6[i] >= Q4[i] && Q6[i] >= Q5[i]))
return average1d;
else if ((Q2[i] <= Q1[i] && Q2[i] <= Q3[i] && Q2[i] <= Q4[i] && Q2[i] <= Q5[i] && Q2[i] <= Q6[i]) &&
(Q1[i] >= Q2[i] && Q1[i] >= Q3[i] && Q1[i] >= Q4[i] && Q1[i] >= Q5[i] && Q1[i] >= Q6[i]))
return average2;
else if ((Q2[i] <= Q1[i] && Q2[i] <= Q3[i] && Q2[i] <= Q4[i] && Q2[i] <= Q5[i] && Q2[i] <= Q6[i]) &&
(Q3[i] >= Q2[i] && Q3[i] >= Q1[i] && Q3[i] >= Q4[i] && Q3[i] >= Q5[i] && Q3[i] >= Q6[i]))
return average2a;
else if ((Q2[i] <= Q1[i] && Q2[i] <= Q3[i] && Q2[i] <= Q4[i] && Q2[i] <= Q5[i] && Q2[i] <= Q6[i]) &&
(Q4[i] >= Q1[i] && Q4[i] >= Q2[i] && Q4[i] >= Q3[i] && Q4[i] >= Q5[i] && Q4[i] >= Q6[i]))
return average2b;
else if ((Q2[i] <= Q1[i] && Q2[i] <= Q3[i] && Q2[i] <= Q4[i] && Q2[i] <= Q5[i] && Q2[i] <= Q6[i]) &&
(Q5[i] >= Q1[i] && Q5[i] >= Q2[i] && Q5[i] >= Q3[i] && Q5[i] >= Q4[i] && Q5[i] >= Q6[i]))
return average2c;
else if ((Q2[i] <= Q1[i] && Q2[i] <= Q3[i] && Q2[i] <= Q4[i] && Q2[i] <= Q5[i] && Q2[i] <= Q6[i]) &&
(Q6[i] >= Q1[i] && Q6[i] >= Q2[i] && Q6[i] >= Q3[i] && Q6[i] >= Q4[i] && Q6[i] >= Q5[i]))
return average2d;
else if ((Q3[i] <= Q1[i] && Q3[i] <= Q2[i] && Q3[i] <= Q4[i] && Q3[i] <= Q5[i])&&
(Q1[i] >= Q2[i] && Q1[i] >= Q3[i] && Q1[i] >= Q4[i] && Q1[i] >= Q5[i] && Q1[i] >= Q6[i]))
return average3;
else if ((Q3[i] <= Q1[i] && Q3[i] <= Q2[i] && Q3[i] <= Q4[i] && Q3[i] <= Q5[i])&&
(Q2[i] >= Q1[i] && Q2[i] >= Q3[i] && Q2[i] >= Q4[i] && Q2[i] >= Q5[i] && Q2[i] >= Q6[i]))
return average3a;
else if ((Q3[i] <= Q1[i] && Q3[i] <= Q2[i] && Q3[i] <= Q4[i] && Q3[i] <= Q5[i])&&
(Q4[i] >= Q1[i] && Q4[i] >= Q2[i] && Q4[i] >= Q3[i] && Q4[i] >= Q5[i] && Q4[i] >= Q6[i]))
return average3b;
else if ((Q3[i] <= Q1[i] && Q3[i] <= Q2[i] && Q3[i] <= Q4[i] && Q3[i] <= Q5[i])&&
(Q5[i] >= Q1[i] && Q5[i] >= Q2[i] && Q5[i] >= Q3[i] && Q5[i] >= Q4[i] && Q5[i] >= Q6[i]))
return average3c;
else if ((Q3[i] <= Q1[i] && Q3[i] <= Q2[i] && Q3[i] <= Q4[i] && Q3[i] <= Q5[i])&&
(Q6[i] >= Q1[i] && Q6[i] >= Q2[i] && Q6[i] >= Q3[i] && Q6[i] >= Q4[i] && Q6[i] >= Q5[i]))
return average3d;
else if ((Q4[i] <= Q1[i] && Q4[i] <= Q2[i] && Q4[i] <= Q3[i] && Q4[i] <= Q5[i] && Q4[i] <= Q6[i])&&
(Q1[i] >= Q2[i] && Q1[i] >= Q3[i] && Q1[i] >= Q4[i] && Q1[i] >= Q5[i] && Q1[i] >= Q6[i]))
return average4;
else if ((Q4[i] <= Q1[i] && Q4[i] <= Q2[i] && Q4[i] <= Q3[i] && Q4[i] <= Q5[i] && Q4[i] <= Q6[i])&&
(Q2[i] >= Q1[i] && Q2[i] >= Q3[i] && Q2[i] >= Q4[i] && Q2[i] >= Q5[i] && Q2[i] >= Q6[i]))
return average4a;
else if ((Q4[i] <= Q1[i] && Q4[i] <= Q2[i] && Q4[i] <= Q3[i] && Q4[i] <= Q5[i] && Q4[i] <= Q6[i])&&
(Q3[i] >= Q2[i] && Q3[i] >= Q1[i] && Q3[i] >= Q4[i] && Q3[i] >= Q5[i] && Q3[i] >= Q6[i]))
return average4b;
else if ((Q4[i] <= Q1[i] && Q4[i] <= Q2[i] && Q4[i] <= Q3[i] && Q4[i] <= Q5[i] && Q4[i] <= Q6[i])&&
(Q5[i] >= Q1[i] && Q5[i] >= Q2[i] && Q5[i] >= Q3[i] && Q5[i] >= Q4[i] && Q5[i] >= Q6[i]))
return average4c;
else if ((Q4[i] <= Q1[i] && Q4[i] <= Q2[i] && Q4[i] <= Q3[i] && Q4[i] <= Q5[i] && Q4[i] <= Q6[i])&&
(Q6[i] >= Q1[i] && Q6[i] >= Q2[i] && Q6[i] >= Q3[i] && Q6[i] >= Q4[i] && Q6[i] >= Q5[i]))
return average4d;
else if ((Q5[i] <= Q1[i] && Q5[i] <= Q2[i] && Q5[i] <= Q3[i] && Q5[i] <= Q4[i] && Q5[i] <= Q6[i])&&
(Q1[i] >= Q2[i] && Q1[i] >= Q3[i] && Q1[i] >= Q4[i] && Q1[i] >= Q5[i] && Q1[i] >= Q6[i]))
return average5;
else if ((Q5[i] <= Q1[i] && Q5[i] <= Q2[i] && Q5[i] <= Q3[i] && Q5[i] <= Q4[i] && Q5[i] <= Q6[i])&&
(Q2[i] >= Q1[i] && Q2[i] >= Q3[i] && Q2[i] >= Q4[i] && Q2[i] >= Q5[i] && Q2[i] >= Q6[i]))
return average5a;
else if ((Q5[i] <= Q1[i] && Q5[i] <= Q2[i] && Q5[i] <= Q3[i] && Q5[i] <= Q4[i] && Q5[i] <= Q6[i])&&
(Q3[i] >= Q2[i] && Q3[i] >= Q1[i] && Q3[i] >= Q4[i] && Q3[i] >= Q5[i] && Q3[i] >= Q6[i]))
return average5b;
else if ((Q5[i] <= Q1[i] && Q5[i] <= Q2[i] && Q5[i] <= Q3[i] && Q5[i] <= Q4[i] && Q5[i] <= Q6[i])&&
(Q4[i] >= Q1[i] && Q4[i] >= Q2[i] && Q4[i] >= Q3[i] && Q4[i] >= Q5[i] && Q4[i] >= Q6[i]))
return average5c;
else if ((Q5[i] <= Q1[i] && Q5[i] <= Q2[i] && Q5[i] <= Q3[i] && Q5[i] <= Q4[i] && Q5[i] <= Q6[i])&&
(Q6[i] >= Q1[i] && Q6[i] >= Q2[i] && Q6[i] >= Q3[i] && Q6[i] >= Q4[i] && Q6[i] >= Q5[i]))
return average5d;
else if ((Q6[i] <= Q1[i] && Q6[i] <= Q2[i] && Q6[i] <= Q3[i] && Q6[i] <= Q4[i] && Q6[i] <= Q5[i])&&
(Q1[i] >= Q2[i] && Q1[i] >= Q3[i] && Q1[i] >= Q4[i] && Q1[i] >= Q5[i] && Q1[i] >= Q6[i]))
return average6;
else if ((Q6[i] <= Q1[i] && Q6[i] <= Q2[i] && Q6[i] <= Q3[i] && Q6[i] <= Q4[i] && Q6[i] <= Q5[i])&&
(Q2[i] >= Q1[i] && Q2[i] >= Q3[i] && Q2[i] >= Q4[i] && Q2[i] >= Q5[i] && Q2[i] >= Q6[i]))
return average6a;
else if ((Q6[i] <= Q1[i] && Q6[i] <= Q2[i] && Q6[i] <= Q3[i] && Q6[i] <= Q4[i] && Q6[i] <= Q5[i])&&
(Q3[i] >= Q2[i] && Q3[i] >= Q1[i] && Q3[i] >= Q4[i] && Q3[i] >= Q5[i] && Q3[i] >= Q6[i]))
return average6b;
else if ((Q6[i] <= Q1[i] && Q6[i] <= Q2[i] && Q6[i] <= Q3[i] && Q6[i] <= Q4[i] && Q6[i] <= Q5[i])&&
(Q4[i] >= Q1[i] && Q4[i] >= Q2[i] && Q4[i] >= Q3[i] && Q4[i] >= Q5[i] && Q4[i] >= Q6[i]))
return average6c;
else if ((Q6[i] <= Q1[i] && Q6[i] <= Q2[i] && Q6[i] <= Q3[i] && Q6[i] <= Q4[i] && Q6[i] <= Q5[i])&&
(Q5[i] >= Q1[i] && Q5[i] >= Q2[i] && Q5[i] >= Q3[i] && Q5[i] >= Q4[i] && Q5[i] >= Q6[i]))
return average6d;
if (Q1[i] > Q2[i] && Q1[i] > Q3[i] && Q1[i] > Q4[i] && Q1[i] > Q5[i] && Q1[i] > Q6[i])
return largest1;
else if (Q2[i] > Q1[i] && Q2[i] > Q3[i] && Q2[i] > Q4[i] && Q2[i] > Q5[i] && Q2[i] > Q6[i])
return largest2;
else if (Q3[i] > Q2[i] && Q3[i] > Q1[i] && Q3[i] > Q4[i] && Q3[i] > Q5[i] && Q3[i] > Q6[i])
return largest3;
else if (Q4[i] > Q1[i] && Q4[i] > Q2[i] && Q4[i] > Q3[i] && Q4[i] > Q5[i] && Q4[i] > Q6[i])
return largest4;
else if (Q5[i] > Q1[i] && Q5[i] > Q2[i] && Q5[i] > Q3[i] && Q5[i] > Q4[i] && Q5[i] > Q6[i])
return largest5;
else if (Q6[i] > Q1[i] && Q6[i] > Q2[i] && Q6[i] > Q3[i] && Q6[i] > Q4[i] && Q6[i] > Q5[i])
return largest6;
else
return 0;
}