I need a program who ask for a number of persons (n persons)
and asks for each person's age...
then it should remember the number of person and it's ages...
and then print the different range lists of the persons:
Range 1: 0-18 years
Range 2:19-30 years
Range 3:31-60 years
Range 4:61years or more.
for example this needs to be the output:
enter number of persons:6
enter age for person 1: 35
enter age for person 2: 40
enter age for person 3: 14
enter age for person 4: 78
enter age for person 5: 24
enter age for person 6: 12
Range 1 persons (0-18):
person 3: 14 years
person 6: 12 years
Range 2 persons (19-30):
person 5: 24 years
Range 3 persons (31-60):
person 1: 35 years
person 2: 40 years
#include <iostream>
#include <map>
#include <string>
int main()
{
// A multimap to hold name and age
std::multimap<std::string, int> mPeople;
std::string name;
int age;
// Input name and age
while(std::cin >> name >> age)
mPeople.insert(std::pair<std::string, int>(name, age)); // Insert the name/age pairs
std::cout << "\nRange (0-18):" << std::endl;
for(std::multimap<std::string, int>::const_iterator it = mPeople.begin(); it != mPeople.end(); ++it)
{
// If the age is between 0 and 18. Print out the name and age
if(it->second >= 0 && it->second <= 18)
std::cout << it->first << " " << it->second << std::endl;
}
return 0;
}