Rule 5. Data dominates. If you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident. Data structures, not algorithms, are central to programming.
Have you begun to set up a data type? (And you may want to mention the language -- C or C++.)
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Yes I have begun it.
Then can you post the code of your data structure?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Look, I'm trying to help, and I don't really care for your attitude either. I've told you the best place to start and you refuse to acknowledge it. Building on that, I'd come up with this "pseudocode" (but I don't think in psuedocode because I find that the C languages are wonderful design tools and skip the middleman approach).
void count_by_age_group(struct record* data, int count)
{
int range[5] = {0};
while ( count-- )
{
if ( data->age < 20 )
{
++range[0];
}
else if ( data->age < 30 )
{
++range[1];
}
else if ( data->age < 40 )
{
++range[2];
}
else if ( data->age < 50 )
{
++range[3];
}
else
{
++range[4];
}
}
}
I ain't gonna get all graphical with some silly flowchart when it would essentially say the same thing as this: loop through the data and bump a counter for age ranges -- kinda like the assignment says.
[Don't take this as an insult, I think we've both been rubbed the wrong way.]
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314