Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void studentData(); // declarations
char studentName[24][40],letterGrade[24];
int classData[24][4], tempGrade;
bool end = false;
ifstream inFile;
int main()
{
inFile.open("ClassData.txt");
if (inFile.fail()) // if file fails to open terminate the program.
{
cout << "Failed to open file. Bye!";
return 0;
}
while(end == false) // perform function while eof is false
{
studentData(); // calling function
}
return 0;
}
void studentData()
{
if(inFile >> tempGrade) //priming read
end = true; // if eof set boolean to true
for(int count = 0; count < 24; count++) // loop to increment the first dimenson
{
for(int counter = 0; counter < 4; counter++) // loop to increment the second subscript
{
classData[count][counter] = tempGrade;
cout << classData[count][counter] << " ";
inFile >> tempGrade;
}
inFile.getline(studentName[count],40); // store info for the students name
cout << studentName[count] << "\n";
}
}
Im trying to have a two dimensional array read input from a file and then store the name in a different array. All I get with this program is the first four numbers then a bunch of zero's afterwards. I'll add the file, please this is has been bugging me for the past couple days!