Saving data into an array.

I have this code I want to save into an array:


char testScoreGrade(double totalAvg)
{
if (totalAvg >=90)
return 'A';
else
if ( totalAvg >=80 )
return 'B';
else
if ( totalAvg>=70 )

return 'C';
else
if ( totalAvg >=60 )
return 'D';
else
return 'F';
}



How can I save the data into an array?
What data? There's only one variable you're dealing with: totalAvg. Could you detaliate?
I have this code from a previous class:


#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cstdlib>

using namespace std;

void testScoreAverage(ifstream&, ofstream&, double&);
char testScoreGrade(double totalAvg);

int main( )
{
char filename[50];
double scoreavg;
double average = 0;
int counter = 0;
string name;
// double totalAvg;
ifstream inFile;
ofstream outFile;

//To read and store data
cout << "Enter input file name: ";
cin >> filename;

inFile.open(filename);

if(inFile.fail())
{
cout << "input file did not open please check it\n";

system("pause");

return 1;
}

cout << "Enter output file name: ";
cin >> filename;

outFile.open(filename);


outFile << fixed;
outFile.precision(2);
outFile << "Student Test1 Test2 Test3 Test4 Test5 Average Grade"
<< endl;
while (true)
{
inFile >> name;
if (!inFile)
break;
outFile << setw(10) << left << name;
testScoreAverage(inFile, outFile, scoreavg);
outFile << setw( 10 ) << right << scoreavg;
outFile << setw( 6 ) << right << testScoreGrade(scoreavg)<<endl;
counter++;
average += scoreavg;
}

// output the results
average = average/counter;
outFile << endl << "Class Average = " << average;
inFile.close( );
outFile.close( );
return 0;
}

//A function to calculate the average test score
void testScoreAverage( ifstream& input, ofstream& output, double& scoreavg )
{

scoreavg=0;
int score;
for (int i = 0; i < 5; i++)
{
input >> score;
output << setw(7) << right << score;
scoreavg += score;
}
scoreavg =scoreavg/ 5.0;
}

//A function to calculate the test score grade
char testScoreGrade(double totalAvg)
{
if (totalAvg >=90)
return 'A';
else
if (totalAvg >=80)
return 'B';
else
if (totalAvg>=70)
return 'C';
else
if (totalAvg >=60)
return 'D';
else
return 'F';
}



Part of the instructions say to use a parallel one-dimensional array to store the students' averages and grades. A parallel two-dimensional array to store test scores and a one dimensional array to store students names. How would I incorporate the arrays into this program?
Topic archived. No new replies allowed.