Would appreciate help understanding how to get team totals from a function so that I may determine the winning team in a walking challenge.
I created a file consisting of team name followed by four team members per team (e.g., Ramblers Angie Peter Susan Fred, Trekkers John Adam Ann Sally). I then read the file and get each walker's steps for a specific # of days. I am able to total each walker's steps, but I want to total the steps for all walkers in a team to determine which team had the most. Everything I've tried gives me back 0 so nothing after that works. Any pointers would be much appreciated.
int walkerSteps(string name, string member);
int main()
{
ifstream inputFile;
inputFile.open("teams.txt");
int totalSteps=0;
while (inputFile >> teamName)
{
cout << "\nTeam " << teamName << " enter your walking counts for: " << endl;
int count = 0;
int sum = 0;
for (int i = 1; i < 3; i++) // Read the four team member's names
{
inputFile >> teamMember;
cout << teamMember << endl;
sum = walkerSteps(teamName, teamMember);
}
}
cout << "The team with the most combined steps is " << teamName << " with "
<< mostSteps << " total steps." << endl;
int teamAverage = totalSteps / 4;
cout << "Team " << teamName << " had an average of " << average << " steps per walker" << endl << endl;
system("pause");
return 0;
}
/* ************ Function Definitions ************** */
int walkerSteps(string name, string member)
{
constint SIZE = 3;
int steps[SIZE];
int total = 0;
int sum = 0;
for (int count = 0; count < SIZE; count++)
{
cout << "Enter number of steps walked on day " << (count + 1) << ": ";
cin >> steps[count];
total += steps[count];
}
cout << "Total steps walked: " << total << endl;
return sum = total;
}
You need a team method to call into the individual walker method. For example (I just substituted fstream with sstream for demo purposes), which you can test at https://repl.it/repls/WarpedTeemingGenres :