I have this project that takes a team name, how many members are on a team and the individual times. I need to output the teamname and times (in seconds) and then the total time of each team. I'm having trouble adding the total team times.

while(infile.peek() !=EOF)
{
	 getline (infile, teamName);
	 infile >> numRunners;

	 cout << teamName << endl;
	 cout << numRunners << endl;

	 for (i=1; i<=numRunners; i++)
	 {
		 infile >> runMinutes >> runSeconds; 
		 runTotal = (runMinutes * 60) + runSeconds; 
		
	  cout << runTotal << endl; //for testing purposes, outputs run times
	  
	 infile.ignore(1);

Recommended Answers

All 3 Replies

It would probably be easier if you stored the times entirely as seconds and then converted to "<minutes>:<seconds>" for display purposes. I don't suspect that these times are likely to exceed the limits of one of the integer or floating-point types.

I thought that I was doing that with line 12:

runTotal = (runMinutes * 60) + runSeconds;

No, what I mean is ditch runMinutes entirely and just use runSeconds.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.