Hi, Im working on a project for school and Im having a little trouble with one of my functions. I need a function to find the highest test score and a function to print the highest test score and the student that has it. The students first and last names, test scores and letter grades are stored in a struct. I got the whole program working except the part where i find the high test and print the student who has it. Here is my code so far.

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

struct studentType
        string fName, lName;
        int Scores;
        int Tests;
        char grade;

studentType students[20];

void StuRead(ifstream &inFile, studentType students[]);
char AssignGrade(studentType students[]);
int Highest(ifstream &inFile, studentType students[]);
void Print(ofstream &outFile, studentType students[]);

main ()

ifstream inFile;
ofstream outFile;


StuRead(inFile, students);
Highest(inFile, students);

Print(outFile, students);
return 0;

void StuRead(ifstream &inFile, studentType students[])
int x;

x = 0;
for (x = 0; x < 20; x++)
  inFile >> students[x].lName
         >> students[x].fName
         >> students[x].Tests;


char AssignGrade(studentType students[])
int score, x;

for(x = 0; x < 20; x++)
        score = students[x].Tests;
        if(score >= 90)
                students[x].grade = 'A';
        else if(score >= 80)
        students[x].grade = 'B';
        else if(score >= 70)
                students[x].grade = 'C';
        else if(score >= 60)
        students[x].grade = 'D';
        students[x].grade = 'F';


int Highest(ifstream &inFile, studentType students[])

int x;
int highTest, sTest;
sTest = 0;
        for(x = 0; x < 20; x++)
          highTest = students[x].Tests;
          if(highTest > sTest)
                sTest = highTest;

        return sTest;

void Print(ofstream &outFile, studentType students[])
int x;

        for(x = 0; x < 20; x++)
                outFile << left << students[x].lName <<", "
                        << students[x].fName <<" "
                        << students[x].Tests <<" " << students[x].grade << endl;

        outFile << "Student with the Highest score: " << endl;


After I get my "Highest" fuction working, would I have to call that by the print funtion? because I can only have 1 print function and it have to output everything. And if i would need to call my "Highest" fuction in my print one, would I have to include the function in my "print" function parameters? im not sure of the syntax for that.

If any1 could help me that would be awsome!:D
If anyone could help me find the problem that would be great

Highest() returns the wrong value -- it should return the index value (value of i loop counter) of the student with the highest grade. You will need to add another variable to keep track of that too.

There are a couple ways to implement those functions:

1) in main(), first call highest() and then pass its return value as another argument to print()

2) in print() add another ifstream argument, just before the last line of print() call highest() then print its return value.

outFile << "Student with the Highest score: " 
        << Highest(ifile, students) << endl;
This question has already been answered. Start a new discussion instead.