# Frequency of numbers in array, Need Help

Hello, I'm in desperate need of some help. I have an assignment that I have no idea how to do. write a program, named agePopulation.cpp, which prints the number of people in different ages. If there are no people in some age, you just ignore this age (you MUST NOT print it out). The age ranges from 1 to 100. In your main program, you keep asking the user to input an age until the user enters -99. After the
user ends his/her inputs, the program prints out the frequency of ages. As mentioned earlier, you do not print out the age if its 0.
This is what I have so far. Im really stuck and have no idea what to do next. Any help would be greatly appreciated.

#include
using namespace std;

typedef int AgesType[100];

void showAges (const AgesType, int);

int main()

{
AgesType ages;
int numberOfAges;
int pos;

pos = 0;
cout << "Please input an age from 1 to 100 inclusive. (or -99 to stop)" << endl;
cin >> ages[pos];

while (ages[pos] != -99 && pos <= 100)
{

if (ages[pos] < 1 || ages[pos] > 100) {
cout<<"invalid input. Please reinput the age"<<endl;
cin>> ages[pos];
}
else
{
cin>> ages[++pos];
}
}
numberOfAges = pos;
showAges(ages, numberOfAges);
return 0;
}

void showAges (const AgesType agesArray, int size)
{
int count;
cout<<"The ages will now be displayed."<<endl;
for(count = 0; count < size; count++)
cout<<"For" << //number of people << <<endl;
}

• : Hello, I'm in desperate need of some help. I have an assignment that
: I have no idea how to do. write a program, named agePopulation.cpp,
: which prints the number of people in different ages. If there are no
: people in some age, you just ignore this age (you MUST NOT print it
: out). The age ranges from 1 to 100. In your main program, you keep
: asking the user to input an age until the user enters -99. After the
: user ends his/her inputs, the program prints out the frequency of
: ages. As mentioned earlier, you do not print out the age if its 0.
: This is what I have so far. Im really stuck and have no idea what to
: do next. Any help would be greatly appreciated.
:
: #include
: using namespace std;
:
: typedef int AgesType[100];
:
: void showAges (const AgesType, int);
:
: int main()
:
: {
: AgesType ages;
: int numberOfAges;
: int pos;
:
: pos = 0;
: cout << "Please input an age from 1 to 100 inclusive. (or -99 to
: stop)" << endl;
: cin >> ages[pos];
:
: while (ages[pos] != -99 && pos <= 100)
: {
:
: if (ages[pos] < 1 || ages[pos] > 100) {
: cout<<"invalid input. Please reinput the age"<<endl;
: cin>> ages[pos];
: }
: else
: {
: cin>> ages[++pos];
: }
: }
: numberOfAges = pos;
: showAges(ages, numberOfAges);
: return 0;
: }
:
: void showAges (const AgesType agesArray, int size)
: {
: int count;
: cout<<"The ages will now be displayed."<<endl;
: for(count = 0; count < size; count++)
: cout<<"For" << //number of people << <<endl;
: }
:
:
:

//Use this code for the Assignment.

#include "stdafx.h"

#include <iostream>
#include

using namespace std;

map Ages;

void showAges ();

int main()
{
int iAge = 0;
cout << "Please input an age from 1 to 100 inclusive. (or -99 to stop)" << endl;
cin >> iAge;

while (iAge != -99)
{
if (iAge < 1 || iAge > 100)
cout<<"invalid input. Please reinput the age"<<endl;
else
{
Ages[iAge]++;
}
cin >> iAge;
}
showAges();
return 0;
}

void showAges ()
{
cout<<"The ages will now be displayed."<<endl;
map<int, int>::iterator mapIter = Ages.begin();

while(mapIter != Ages.end())
{
cout<<"For Age "<<mapIter->first<<","<<" # People is "<<mapIter->second<<endl;
mapIter++;
}
}