This is still the readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany) assignment. I've hit a small snag. This piece of the code works....kind of. When the program is run it prints out the table and stuff, however, when printing the grade it doesn't do it correctly. If I take away the for-loop code for printGrade and just leave the if statements, then hardcode 'int i = #', where # = a number from 0 - 21, it will print that one id and score repeatedly as well as the correct "grade" with it. But if left as is, it doesn't print "grade" correctly.
Not sure where the issue lies with this one.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
void printTable(int score[], int id[], int count)
{
void printGrade(int oneScore, float average);
const int MAX_SIZE = 21;
int oneScore = 0;
float average = 0;
string grade;
id[MAX_SIZE];
score[MAX_SIZE];
cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl;
//for(count = 0; count < MAX_SIZE; count++)
//{
printGrade(oneScore,average);
//}
}
void printGrade(int oneScore, float average)
{
const int MAX_SIZE = 21;
int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121};
int scores[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0};
oneScore = 0;
average = 0;
string grade;
for(int i = 0; i < MAX_SIZE; i++)
{
oneScore = oneScore + scores[i];
average = oneScore / MAX_SIZE;
if(scores[i] > average + 10)
{
grade = "outstanding";
}
else if(scores[i] < average - 10)
{
grade = "unsatisfactory";
}
else
{
grade = "satisfactory";
}
cout << left << setw(9) << id[i] << setw(9) << scores[i] << setw(9) << grade << endl;
}
}
int main()
{
const int MAX_SIZE = 21;
int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121};
int score[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0};
int count = 0;
int oneScore = 0;
float average = 0;
printTable(score, id, count);
return 0;
}