Your problem looks like it has something to do with this conversion into an integer, which if it is, is an unusual way of reading in numerical data from a file.
Show us the whole program and a sample of the data you are using. Also it might be an idea to show exactly what you are calculating and what the numbers mean - presumably they are the output of some variable.
I'd say the use of eof() as the loop condition is a problem.
Try replacing this:
14 15 16 17
while (!megaFile.eof( ))
{
getline(megaFile, activity, ',');
getline(megaFile, distance);
with this:
14 15
while (getline(megaFile, activity, ',') && getline(megaFile, distance))
{
In the first version, even if one or both of the getline statements fail, the rest of the loop will still be executed. The second enters the body of the loop only when data has successfully been read from the file.