Hi everyone. I'm a bit of a noob at C++, I took the first level of this class 2 years ago and I'm tying to remember everything. I'm having a problem with a program I'm trying to write. I need to average the grades of each student and then print them in a column. I have to print the grade book (with the average) as a function.
The output should look similar to:
Name Grades Average
Baker 89 77 91 85
Here's what I have so far:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
ifstream inFile;
//Function Prototypes.
void get_Info (string students[], int grades[][3]);
void Prt_Gradebook (string students[], int grades[][3]);
int main ()
{
string students[5]; //Array of students.
int grades[5][3]; //2D array for grades.
get_Info (students, grades); //
Prt_Gradebook (students, grades);//Print the gradebook and the avg for each student.
system ("PAUSE");
return 0;
}
void get_Info (string students[], int grades[][3])
{
inFile.open("QuizData.txt");
for (int r=0; r < 5; r++)
{ inFile >> students[r];
for (int c=0; c < 3; c++)
inFile >> grades[r][c];
}
}
void Prt_Gradebook (string students[], int grades[][3])
{
for (int r=0; r < 5; r++)
{
cout << students[r]<< setw(5)<< " ";
for (int c=0; c < 3; c++)
{
cout << setw(5) << grades[r][c]<< " ";
for (int r=0; r < 5; r++)
{
int sum=0;
int avg;
sum += grades[r][c];
}
}
cout << endl;
}
}
I have it printing the names and grades arrays fine, it's when I try to sum, average and then put the averages into a new column that I get terribly confused. I took out what I had that was truly messed up.
Help please!