Report card / gpa

Hello, I am having difficulty on my assignment and have no idea what is wrong or where to fix my code. The assignment is inputting data from a file into arrays, calculating the GPA, and displaying it neatly. I could use some hints on to why it is not working. My professor isn't the best, and I can't seem to wrap my brain around what is wrong.

The "StudentRecords.txt" file reads as:
12546 Amy CS1 4 81
13455 Bill CS1 4 76
14328 Jim CS1 4 64

12546 Amy CS2 4 90
13455 Bill CS2 4 85
14328 Jim CS2 4 71

12546 Amy CS3 3 90
13455 Bill CS3 3 75
14328 Jim CS3 3 69
14388 Henry CS3 3 80
15667 Peter CS3 3 45

My code:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cmath>

using namespace std;

const int iStudSize = 999;
const int iMaxCourseAmt = 99;

struct Student
{
int iId;
string sName;
string sCourseArr[iMaxCourseAmt];
int iCreditArr[iMaxCourseAmt];
int iScoreArr[iMaxCourseAmt];
int iGradeArr[iMaxCourseAmt];
};

// Converts score to GPA
int getGrade(int iScore)
{
Student data;
int iGrade = -1;

if(iGrade == -1)
{
iGrade = ((data.iCreditArr[1] * iScore) + (data.iCreditArr[1] * iScore))/(data.iCreditArr[1]+ data.iCreditArr[2] + data.iCreditArr[3]);
}
return iGrade;
}


//Display report for ALL students
void doReport(Student studArr[], int iCount)
{

int i;
for(i=0; i < iCount; i++)
{
if(studArr[i].iId != -1)
{
printf("%7s\n", studArr[i].sName.c_str());
printf("%10s %5s %5s %5s \n", "Course", "Credit", "Score", "Grade");
printf("%10s %5s %5s %5s \n", "------", "------", "-----", "-----");
}
}
return;
}

//Using the given iID, the function returns the index of the student.
//If the student does not exist in the array, -1 is returned
int getStudIndex(Student studArr[], int iId)
{
int i = 0;
while (studArr[i].iId != -1)
{
if (studArr[i].iId == iId)
return i;
else
i++;
}

return -1;
}

// Using the given iStudIndex, the function returns the index of the first available spot for recording scores
// If no any course has been recorded, then 0 is returned.
int getCourseIndex(Student studArr[], int iStudIndex)
{
int i = 0;


while(iStudIndex == -1)
{
if (studArr[i].sCourseArr != '\0')
return i;
else
i++;
}

return i;
}


//Initialize all int elements in the array with -1
void initArray(Student studArr[])
{

for (int i =0; i< iStudSize; i++)
{
studArr[i].iId = -1;
for (int j = 0; j < iMaxCourseAmt; j++)
{
studArr[i].iCreditArr[j] = -1;
studArr[i].iScoreArr[j] = -1;
studArr[i].iGradeArr[j] = -1;
}

}

return;
}


int main()
{

ifstream inputFile;
string sFilePath = "C:\\Users\\plapat\\Desktop\\StudentRecords.txt";

int iId, iScore, iCredit, iGrade;
string sName, sCourse;
int iStudCount = 0;

Student studArr[iStudSize]; //Instantiate student array of size 999
initArray(studArr);

inputFile.open(sFilePath.c_str());

while (inputFile >> iId >> sName >> sCourse >> iCredit >> iScore) //Process one row at each iteration
{
iGrade = getGrade(iScore);

int iStudIndex = getStudIndex(studArr, iId);

if (iStudIndex == -1) // The student does not exist in the array
{

}
else // Exist
{
getCourseIndex(studArr, iStudIndex);

}

}

doReport(studArr, iStudCount);
inputFile.close();

return 0;
}



What's the difficulty?
Is it not outputting as expected, or getting any errors? If so, where?
And please put your code in tags.
Topic archived. No new replies allowed.