Taking the sum of numbers from a file, after parsing

Whenever I try to take the sum of movies times from this file:

1
2
3
4
5
2016 116 303.1 Passengers 
2014 169 677.5 Interstellar 
2015 141 630.2 The Martian 
2013 91 723.2 Gravity 
2016 116 203.4 Arrival


I end up with this output:

116

285

426

517

633



This is my function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Movie::test()
{
        int year;
	int time = 0; 
        double gross; 
	int sumTime = 0;
	while (inMovie >> year >> time >> gross)
	{
		string name;
		if (getline(inMovie >> ws, name))
		{
			cout << (sumTime += time) << "\n\n";
		}
	}
}



I figured out that my function is adding 116+0, then 116+169, then 116+169+141, and so on, but I can't figure out how to make the program read the sum of ALL of the numbers at one time. All I want to display is 633. Any help is greatly appreciated, thank you.
Last edited on
Instead of outputting the time in each loop iteration just sum it up and dispay it at the the end.
1
2
if (getline(inMovie >> ws, name))
  sumTime += time;

After the while loop print sumTime.
Last edited on
Topic archived. No new replies allowed.