How to Collect scores with Maps and Text files

This was the assignment i recieved. I tried giving a try but I'm stuck and need some guidance. I look everywhere trying to learn more about maps and f streams to see if it would help me out but i'm still suck
For this assignment, you will write a program to analyze some formatted data in a text file. Scores for 200 games (one game per line) in an accountants' kickball league are provided here: scores.txt.

http://glasslab.engr.ccny.cuny.edu/u/jcross/csc103/code/scores.txt

(They are in a standardized format with the score for one match on each line, with the score for each team after its name.) Your job is to write a program which parses this file, keeping a running count of how many points are scored by each team (PF) and against each team (PA), printing those values out on the console in this format:
Baboons PF: 3360 PA: 3767
(After putting everything in a map. I'm suppose to output the total points the team scored and the total points all of the opponents scored)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #include <fstream>
#include <iostream>
#include <map>

using namespace std;

int main()
{

    map<string, double> team;
string line;
    // Read data from file
    ifstream input("scores.txt");
    while ( getline (input,line) )
    {
        string teamId;
        input >> teamId;


        int score;
        input >> score;

        int total;
        total += score;

        team[teamId] = total;
    }


    // Output results to console


for( map<string, double>::iterator ii=team.begin(); ii!= team.end(); ++ii)
   {
       cout << "Team: "<< endl;
       cout << (*ii).first <<endl;
    cout << "Total score: "<< endl;
       cout << (*ii).second << endl;
   }
}


Any advice on how to go about this or examples would be helpful. plus any other advice for how to learn c++ for beginners would be helpful too.
Last edited on
Topic archived. No new replies allowed.