Calling a Function within a function

Pages: 12
It reads:
Hooray!!!
Type : run,5.3
"istance : "skierg,1

hi there
Hooray!!
Type : erg,2
"istance : "run,7

hi there
Hooray!!!
Type : skierg, 0.54
"istance : "skierg, 0.34

And so on, reading every line, but two at a time: it seems effective, except that it takes two values instead of one at a time.
Modify the input file like this :
run
5.3
skierg
1
erg
2
run
7
skierg
0.54
skierg
0.34
run
2
erg
1
erg
0.75
run
9

We are going back a bit, and we should so that we can fully diagnose the problem. In the first version, apply this code :
while (getline(megaFile, activityType))

Here is the second version :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void User:: ProcessData(string fileName)
{
string activityType;
double activityDistance = 0;
string distance;
ifstream megaFile;

megaFile.open(fileName);
while (megaFile >> activityType)
{
cout << "Hooray!!!" << endl;

megaFile >> activityDistance;

cout << "Type : (" << activityType << ")" << endl;
cout << "Distance : \"" << activityDistance << "\"" << endl << endl;

addActivity(activityType, activityDistance);
}
megaFile.close();
}


Test this input file with your two code versions and see which will work. And let us see the output.
Unfortunately, I am doing this for an assignment- it will be submitted to an autograder, which will provide its own files that I will be unable to alter.
That code printed:
Hooray!!!
Type : (activity, distance)
Distance : "0"

hi there

Ah, figured it out- changed the while loop to
while (!megaFile.eof( ))
and added a header skipper before it, and it now includes the whole page.
Thank you.
Finally. Glad it helped :)
Topic archived. No new replies allowed.
Pages: 12