-4

I am trying to write a program that reads lines from a file that contains a person's name, team color, and score from a baseball league. Need to sort the input into two parallel arrays, figure out which team scored more, then print the data of the team that scored more.

I can't figure out:

  1. How to read the file because doing getline(member, team, score) isn't working (there are no spaces). I declared variables and set to zero, but do I need to do a prototype too?

  2. We need to sort the file into the parallel arrays using an if statement inside a while loop, so it would be: if(team == color), then it would need to put the score in one array, and the member name in the other for that color. But no idea how to write this out, since I'm not printing anything and just want to store it, and then sum the scores. Then I need to increase accumulator for each, but again not sure how to do that with multiple teams.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
existence
  • 1
  • 2

1 Answers1

0
  1. You'll need to write a parser for your file format, and put the data somewhere. Which leads us onto 2.

  2. Instead of declaring multiple arrays, use a structure or similar to store data that belongs together.

-

struct Player
{
    std::string name;
    std::string uniformColour;
    int score;
};

// Parse players from file into a std::vector<Player> or similar.

This is all very simple stuff -- I suggest you read some C++ tutorials and books aimed at beginners.

Bernard
  • 45,296
  • 18
  • 54
  • 69