Problem using STL library (-map)

Please can you help me with this problem that uses the STL Library(-map):
Create a string of n people, name and age. Calculate the average age of all people in the string. Show the string.
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

"a string of people" sounds somehow odd. "A string" usually means text. Perhaps a "list" or "table" would be more appropriate term?

Where does it say that the task "uses" something? What is this (-map) that you refer to?

It would be more correct to say that you are expected to implement the program with C++ Standard Library.
Read C++ map tutorial at the following link:

Compile, run the example program given on the above link webpage.

Modify the example program to suit your requirements.

To calculate average age, you have to modify the while loop code on lines 17 to 21 of the above link's example and add C++ code to sum ages and calculate average.

At the end of above web page, there are links to other related articles to read and understand various details about C++ map, set etc.
Last edited on
If you have the input data is a text line consisting of name and age then use the example program given on following web page link:

Topic archived. No new replies allowed.