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];
}
}
}