Hello I'm new to C++ and am trying my best to learn the language. Could someone please let me know why my program is not working. I have a feeling that I'm not passing values to and from functions. The program compiles and runs, but it just gives me a black prompt screen and then when I press a key, the program then closes. What am I doing wrong?

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

using namespace std;


const int ARRAY_SIZE = 20;

struct studentType
{
    string studentFName[ARRAY_SIZE];
    string studentLName[ARRAY_SIZE];
    int testScore[ARRAY_SIZE];
    char grade[ARRAY_SIZE];
};


void readIn(studentType& student);
void assignGrade(studentType& student);
int findHighestScore(studentType& student);
void printHighScorers(studentType& student, int highScore);

int main()
{
    int highestScore;

    ifstream infile;
    ofstream outfile;
    char fileName[10];

    infile.open("indata.txt");
    outfile.open("outdata.out");

    void readIn(studentType& student);
    void assignGrade(studentType& student);
    int findHighestScore(studentType& student);

    infile >> highestScore;


    void printHighScorers(studentType& student, int highScore);
    cin.get();

    infile.close();
    outfile.close();

    return 0;
}

void readIn(studentType& student)
{
    int i;
    ifstream infile;
    char fileName[10];

    infile.open("indata.txt");

    for (i=0; i<ARRAY_SIZE;i++)
    {
        cout << "Student [" << (1+i) << "/" << ARRAY_SIZE << "]: Enter the first name and last name: " << endl;
        infile >> student.studentFName[i] >> student.studentLName[i];

        cout << "Enter the student's test score: " << endl;
        infile >> student.testScore[i];
    }
}

void assignGrade(studentType& student)
{
    int i;

    ifstream infile;
    char fileName[10];

    infile.open("indata.txt");

    for (i=0; i<ARRAY_SIZE;i++)
    {

        if (student.testScore[i] >=90)
        student.grade[i] = 'A';
        else if (student.testScore[i] >= 80)
        student.grade[i] = 'B';
        else if (student.testScore[i] >= 70)
        student.grade[i] = 'C';
        else if (student.testScore[i] >= 60)
        student.grade[i] = 'D';
        else
        student.grade[i] = 'F';
    }

    for (i=0; i<ARRAY_SIZE;i++)
    {
        infile >> student.studentLName[i] >> student.studentFName[i] >> student.testScore[i] >> student.grade[i];
        cout << student.studentLName[i] << ", " << student.studentFName[i] << " " << student.testScore[i] << " " << student.grade[i] << endl;
    }
}

int findHighestScore(studentType& student)
{
    int i;
    int max;
    int x;
    int y;
    int highestScore;


    for (i=0; i<ARRAY_SIZE;i++)
    {
        x = student.testScore[i];
        y = max;
        if(x>=y)
            max=x;
        else max = y;
    }

    highestScore = max;
    return highestScore;

}

void printHighScorers(studentType& student, int highScore)
{
     int i;

     ofstream outfile;
     char fileName[10];

     outfile.open("outdata.txt");

     for(int i=0; i<ARRAY_SIZE; i++)
     {
            if (student.testScore[i] == highScore)
           {
               outfile << student.studentLName[i] << ", " << student.studentFName[i] << " " << student.testScore[i] << " " << student.grade[i];
               cout << student.studentLName[i] << ", " << student.studentFName[i] << " " << student.testScore[i] << " " << student.grade[i];
           }
      }
}

Line 43 seems way off. I'll take your word that this compiles and runs, but even so, line 43 is definitely wrong. I'm assuming that line 43 is supposed to be a function call. However, it is NOT a function call. Function calls don't have the return type and parameter types. Function DEFINITIONS do, but not function CALLS.

Now that I look at it, the same applies to lines 36 to 38. If you can't see what is wrong by looking at those lines, then that means you don't understand how to call functions yet, so you'll want to set aside this program and take some tutorials on how to call functions in C++, particularly how to pass parameters by reference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.