I've been trying to read a text file with a loop. But for some reason, it never seems to get the integer values correct. I always end up with garbage values.
while(!file.eof()) // I've also tried other variations of this while loop, none of which worked either
{
// ifstream, string, char, string, int
file >> name >> sex >> data >> score;
std::cout << name << std::endl;
if (sex == 'F')
{
femaleAverage += score;
femaleCount++;
}
else
{
maleAverage += score;
maleCount++;
}
if (data.compare("CC"))
{
comAverage += score;
comCount++;
}
else
{
uniAverage += score;
uniCount++;
}
}
Here is what the text file looks like:
Bailey M CC 68
Harrison F CC 71
Grant M UN 75
Peterson F UN 69
Hsu M UN 79
Bowles M CC 75
Anderson F UN 64
Nguyen F CC 68
Sharp F CC 75
Jones M UN 75
McMillan F UN 80
Gabriel F UN 62