Using a struct variable of type

Hi ya all,
I've got a HW and I'm so stuck.
Okay, so here's what my prof wants us to do, "Write a program that prompts to read students' names followed by their test scores (1 test score for every student). The program should output to the screen, the student's name followed by the test score, and the relevant grade. At the end, it should also find and print the highest test score and the name of the student with the highest test score, the lowest test score and the name of the student with the lowest test score, and the average of the test scores."

for example,
John Smith 75 C
Sue Jones 90 A
Ray Adams 85 B

I should use a struct variable type as well as an array of structs. The input data should be read either from a file or from a user. Also I need to use at least 2 functions and pass by array to the functions as parameters.

Here's what I've done so far.

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

using namespace std;

struct StudentType
{
string studentFName;
string studentLName;
int testScore;
char grade;
};

const int maxStudents = 5;
int loadData(istream& input, StudentType students[], int maxStudents);
int findHighest(StudentType students[], int nStudents);
int findLowest(StudentType students[], int nStudents);
char letGrades(char grade);
void calGrades(StudentType students[], int nStudents);
void topScores(int highestScore, StudentType students[], int nStudents);

int main()
{
int numOfStudents = 0;
ifstream inFile;
cout << "Enter the student's first name, last name, and test score. " << endl;
inFile.open("studentTestScores.txt");
if (!inFile)
{
cout << "Cannot open the input file." << endl;
cout << "Program terminated." << endl;
system("pause");
return 0;
}
else if (numOfStudents >= 5)
{
cout << "Sorry, you can't put any more students." << endl;
}
else if (inFile)
{
//I need to call all the functions as well as the struct type.
}

}

int loadData(StudentType students[])
{
int student = 0;
ifstream inputFile;
while (!inputFile.eof() && student < maxStudents)
{
// What should I put here?
}
return student;
}

void calGrades(StudentType students[], const int nStudents)
{
int i;
for (i = 0; i < nStudents; i++)
{
students[i].grade = letGrades(students[i].testScore);
}
}

int findHighest(StudentType students[], const int nStudents)
{
int i;
for (i = 0; i < nStudents; i++)
{
students[i].grade = letGrades(students[i].testScore);
}
return i;
}

void topScores(int highestScore, StudentType students[], const int nStudents)
{
int i;
cout << highestScore << letGrades << " is the highest score within a group of " << nStudents << " students." << endl;
for (i = 0; i < nStudents; i++)
{
if (students[i].testScore == highestScore)
{
cout << students[i].studentLName << ", " << students[i].studentFName << endl;
}
}
}

char letGrades(char grade)
{
char charGrades;
if (grade >= 90)
{
charGrades = 'A';
}
else if (grade >= 80)
{
charGrades = 'B';
}
else if (grade >= 70)
{
charGrades = 'C';
}
else if (grade >= 60)
{
charGrades = 'D';
}
else
{
charGrades = 'F';
}
return charGrades;
}

The problem is, calling all the functions in the main didn't work and I don't know what should put in loadData function in order to read from a file.

here's the inputfile.
John Smith 75
Sue Jones 90
Ray Adams 85

Help me out Plz!!
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) What do you mean by "didn't work"? Do you get a compiler error? A run-time crash? Something else?
Topic archived. No new replies allowed.