Okay so I know this program has a lot of problems at the moment. Im going to figure it out soon. But my main concern is why I can not open a simple txt file to read the info in it. this is what I have. I need it to be read right away and cannot figure it out.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
readStuData(file, students, scores, id, tooMany);
studstruct(id, scores, studnum);
getavg (counter, sum, scores, avg, students);
getgrade(counter, students, scores, avg, grade);
PrintTable(counter, students, id, scores, grade);
}
void readStuData(string file,int& students, int scores[MAX], int id[MAX], bool &tooMany)
{
cout << "Enter the file name: ";
cin >> file;
infile.open(file.c_str());
if (infile.fail()) cout << "Error. Cannot open " << file;
while (!infile.eof())
{
infile >> students;
counter++;
}
students = counter;
tooMany = (students > MAX);
if (tooMany == true) cout << "There are too many students.";
for (counter = 0; counter < students; counter++)
{
infile >> id[counter] >> scores[counter];
}
}
void studstruct(int id[MAX], int scores[MAX], int studnum[MAX])
{
for (counter = 0; counter < students; counter++)
{
struct student;
{
int id[MAX];
int scores[MAX];
int studnum = counter + 1;
}; stu[MAX];
}
}
void getavg(int counter, float sum, int scores[MAX], float avg, int students)
{
for (counter = 0; counter < students; counter++)
{
sum = scores[counter] + sum;
}
avg = sum / students;
}
void getgrade(int counter, int students, int scores[MAX], float avg, char grade[MAX])
{
for (counter = 0; counter < students; counter++)
{
if (scores[counter] <= avg + 10 && scores[counter] >= avg - 10) grade = "Satisfactory";
else if (scores[counter] > avg + 10) grade = "Outstanding";
else if (scores[counter] < avg - 10) grade = "Unsatisfactory";
}
}
void PrintTable(int counter, int students, int id[MAX], int scores[MAX], char grade[MAX])
{
for (counter = 0; counter < students; counter++)
{
cout << "ID Score Grade\n";
cout << "----------------------------------";
cout << id[counter] << " " << scores[counter] << " " << grade[counter];
}
}