Apr 12, 2016 at 9:48pm UTC
I am trying to pull each grade from the void getData() Function but it's only pulling the last grade. I understand that the grades are in a while loop and all but the last grade may not show in the rest of the program... but i was wondering if it was possible for it to print each grade in the void getData Function.
Please and Thank you
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
void getData(string fileName, int scores[], int &grade, int &numStudents)
{
ifstream inFile;
inFile.open(fileName.c_str());
string key;
inFile >> key;
scores[11];
for( int i = 0; i<scores[i]; i++)
{
scores[i] = 0;
}
numStudents = 0;
string exam;
while(( inFile >> exam) && exam != "" )
{
numStudents++;
grade = 0;
for( int i = 0; i < 10; ++i )
if( exam[i] == key[i] )
grade++;
cout << "student " << numStudents << " - " << grade << endl;
}
cout << grade ;
}
double average (int scores[], int &grade, int &numStudents)
{
double avg = 0;
double sum = 0;
for (int i = 0; i < numStudents; i++)
{
sum = sum + grade;
}
avg =(sum)/(numStudents);
return avg;
}
int findHighest(int scores[], int grade ,int numStudents)
{
int Highest = 0;
for (int i = 0; i < numStudents; i++)
{
if (scores[grade] > scores[Highest])
Highest = i;
}
return Highest;
}
int findLowest(int scores[], int &grade ,int &numStudents)
{
int Lowest = 0;
for (int i = 0; i < numStudents; i++)
{
if (scores[grade] < scores[Lowest])
Lowest = i;
}
return Lowest;
}
int main()
{
const int MAX = 11;
int scores[MAX];
const string fileName = "grade_data.txt";
int numStudents = 0;
int grade = 0;
getData(fileName,scores, grade, numStudents);
int highest = findHighest(scores, grade, numStudents);
cout << "high score - " << highest << endl;
int lowest = findLowest(scores, grade, numStudents);
cout << "low score - " << lowest << endl;
double avg = average (scores, grade, numStudents);
cout << "mean score - " << avg << endl;
return 0;
}