No, you're not slow, I'm just getting too far ahead of myself and trying to help you fix everything at once, apologies.
declare I out here so we can keep track of it
for loop #1 (over 0 to 50)
{
keep a running total of sum (which you are doing just fine
if (over 18)
I--; (bring it back by 1 position (we want to know how many we stepped back in the end so we can use it on the next loop)
}
Average = calculation;
for(make it small i=0 to I)
{
output age[i] which you are doing just fine
}
output average and message