I am having trouble in including the class average and the individual averages. This is what I have so far. Any help would be appreciated.
[#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const int SIZE = 1000;
string studentID[SIZE];
string flag = "0";
double quiz1[SIZE];
double quiz2[SIZE];
double quiz3[SIZE];
double quiz4[SIZE];
double average[SIZE] = (quiz1+quiz2+quiz3+quiz4)/4;
int i = 0;
while (i < SIZE)
{
cout << "Student Id (-1 to exit): ";
cin >> flag;
if (flag == "-1")
break;
studentID[i] = flag;
cout << "Input quiz1: ";
cin >> quiz1[i];
cout << "Input quiz2: ";
cin >> quiz2[i];
cout << "Input quiz3: ";
cin >> quiz3[i];
cout << "Input quiz4: ";
cin >> quiz4[i];
cout << average << endl;
i++;
}
ofstream output;
output.open("Grades.txt");
for (int j = 0; j < i; j++)
{
cout << "Student ID: " << fixed << setprecision(2) << studentID[j] << endl;
cout << "Quiz 1: " << fixed << setprecision(2) << quiz1[j] << endl;
cout << "Quiz 2: " << fixed << setprecision(2) << quiz2[j] << endl;
cout << "Quiz 3: " << fixed << setprecision(2) << quiz3[j] << endl;
cout << "Quiz 4: " << fixed << setprecision(2) << quiz4[j] << endl;
cout << endl;
}
for (int j = 0; j < i; j++)
{
output << studentID[j] << endl;
output << quiz1[j] << endl;
output << quiz2[j] << endl;
output << quiz3[j] << endl;
output << quiz4[j] << endl;
}
output.close();
ifstream input;
input.open("Grades.txt");
for (int j = 0; j < i; j++)
{
input >> studentID[j];
input >> quiz1[j];
input >> quiz2[j];
input >> quiz3[j];
input >> quiz4[j];
}
input.close();
for (int j = 0; j < i; j++)
{
cout << "Student ID: " << fixed << setprecision(2) << studentID[j] << endl;
cout << "Quiz 1: " << fixed << setprecision(2) << quiz1[j] << endl;
cout << "Quiz 2: " << fixed << setprecision(2) << quiz2[j] << endl;
cout << "Quiz 3: " << fixed << setprecision(2) << quiz3[j] << endl;
cout << "Quiz 4: " << fixed << setprecision(2) << quiz4[j] << endl;
cout << endl;
}
system("Pause");
return 0;
}
]
I am assuming you are in a class. Have you studied struct (structures) yet?
double average[SIZE] = (quiz1+quiz2+quiz3+quiz4)/4;
This does not do what you think it does.
You need to calculate the individual student averages before this statement:cout << average << endl;
Please use code tags when posting your code so that the indentation is preserved.
Last edited on