Okay, so I have my program almost complete. I can get it to do everything except use the computeAverage. I know it works because if I hard code the arrays, I can utilize that and it will work. However, I am having to utilize what I pull from a .txt file and I can't figure out quite yet how to compute those numbers.
Here is what I have:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int MAX_SIZE = 21; // Declared by professor
void readStudentData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
void printTable(int score[], int id[], int count);
rss.open("studentScoreData.txt",ios::in,ios::binary);
int amountRead = 0;
count = 0;
int oneScore = 0;
float average = 0;
string grade;
if(!rss)
{
cout << "Cannot Open File. If test file has been created rename it studentScoreData." << endl;
}
else
{
printTable(scores, id, count);
while((rss >> id[amountRead] && amountRead < MAX_SIZE) && (rss >> scores[amountRead] && amountRead < MAX_SIZE))
{
amountRead++;
}
for(int i = 0; i < MAX_SIZE; i++)
{
cout << left << setw(9) << id[i] << setw(9) << scores[i] << setw(9) << grade << endl;
}
}
}
float computeAverage(int scores[], int count[])
{
float average = 0;
int sum = 0;
for(int i = 0; i < MAX_SIZE; i++)
sum += scores[i];
average = sum / MAX_SIZE;
return 0;
}
void printTable(int scores[], int id[], int count)
{
void printGrade(int oneScore, float average);
int oneScore = 0;
float average = 0;
string grade;
cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl;
printGrade(oneScore, average);
}
void printGrade(int oneScore, float average)
{
int scores[MAX_SIZE];
oneScore = 0;
average = 0;
int count[MAX_SIZE];
string grade;
computeAverage(scores,count);
for(int i = 0; i < MAX_SIZE; i++)
{
if(scores[i] > average + 10)
{
grade = "outstanding";
}
else if(scores[i] < average - 10)
{
grade = "unsatisfactory";
}
else
{
grade = "satisfactory";
}
//cout << left << setw(9) << grade << endl;
}
}
int main()
{
ifstream rss;
string line;
int scores[MAX_SIZE];
int id[MAX_SIZE];
int count;
bool tooMany;
readStudentData(rss, scores, id, count, tooMany);
return 0;
}