Hope this helps...
program a2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
population = 10;
type
TpopRec = record
age: integer;
agerange: string
end;
Tperson = array[1..population] of TpopRec;
{PRE: true
POST: initialise the ages of all population}
procedure initialise_age(var ftn: Tperson);
var
i: integer;
begin
for i := Low(ftn) to High(ftn) do
begin
writeln('Introduce age of person ', i);
readln(ftn[i].age);
end;
end {initialise_age};
{PRE: true
POST: show the age ranges of all the population}
procedure write_age(ftn: Tperson);
var
AgeGroup: string;
Count: array[1..7] of Integer;
I: Integer;
J: Integer;
begin
{ Initialize Count to 0 (zero) }
for I := 1 to 7 do
begin
Count[I] := 0;
end;
{ Count the number of ages in each of the seven groups. }
for I := Low(ftn) to High(ftn) do
begin
if (ftn[I].age <= 5) and (ftn[I].age >= 0) then
begin
Count[1] := Count[1] + 1;
end
else if (ftn[I].age <= 11) and (ftn[I].age >= 6) then
begin
Count[2] := Count[2] + 1;
end
else if (ftn[I].age <= 18) and (ftn[I].age >= 12) then
begin
Count[3] := Count[3] + 1;
end
else if (ftn[I].age <= 35) and (ftn[I].age >= 19) then
begin
Count[4] := Count[4] + 1;
end
else if (ftn[I].age <= 55) and (ftn[I].age >= 36) then
begin
Count[5] := Count[5] + 1;
end
else if (ftn[I].age <= 65) and (ftn[I].age >= 56) then
begin
Count[6] := Count[6] + 1;
end
else if ftn[I].age >= 66 then
begin
Count[7] := Count[7] + 1;
end;
end;
writeln('the ages are:');
for I := 1 to 7 do
begin
case I of
1: AgeGroup := '0-5: ';
2: AgeGroup := '6-11: ';
3: AgeGroup := '12-18: ';
4: AgeGroup := '19-35: ';
5: AgeGroup := '36-55: ';
6: AgeGroup := '56-65: ';
7: AgeGroup := '66+: ';
end;
write(AgeGroup);
if Count[I] > 0 then
begin
for J := 1 to Count[I] do
begin
write('*');
end;
end;
writeln;
end;
end;
{PRE: ftn not empty}
{Post: Introduce ages for the population}
procedure intro_age(var ftn: Tperson);
var
i, age: integer;
begin
writeln('introduce the ages for the 10 people');
for i := 1 to 10 do
begin
read(age);
ftn[i].age := age;
end;
end;
{PRE: and ftn is not empty
POST: average age for the population}
function average_age(ftn: Tperson): real;
var
av: real;
std: integer;
begin
av := 0;
for std := 1 to population do
begin
av := av + ftn[std].age;
end;
result := av / population;
end;
{PRE: ftn is not empty
POST: maximum age}
function max_age(ftn: Tperson): integer;
var
maximum: integer;
i: integer;
begin
maximum := 0;
for i := 1 to population do
begin
if maximum < ftn[i].age then
maximum := ftn[i].age;
end;
result := maximum;
end;
{PRE: ftn is not empty
POST: minimum age}
function min_age(ftn: Tperson): integer;
var
minimum: integer;
i: integer;
begin
minimum := 1000;
for i := 1 to population do
begin
if minimum > ftn[i].age then
minimum := ftn[i].age;
end;
result := minimum;
end;
{PRE: true
POST: menu with all the functionalities}
procedure menu(var ftn: Tperson; c: char);
begin
case c of
'r', 'R': intro_age(ftn);
'w', 'W': write_age(ftn);
'a', 'A': writeln('Average mark is: ', average_age(ftn));
'M': writeln('Maximum mark is: ', max_age(ftn));
'm': writeln('Minimum mark is: ', min_age(ftn));
else
writeln('error this option has not been recognised');
end;
end; {menu}
procedure prompts;
begin
writeln('Press r to introduce all the ages');
writeln('Press w to show all the ages');
writeln('Press a to calculate average age');
writeln('Press M to calculate maximum age');
writeln('Press m to calculate minumum age');
writeln('Press q to quit');
end;
var
FTN: Tperson;
choice: char;
begin
writeln('Welcome to population statistics');
initialise_age(ftn);
writeln('You have the following options');
prompts;
readln(choice);
while (choice <> 'q') and (choice <> 'Q') do
begin
menu(FTN, choice);
prompts;
readln(choice);
end;
writeln('Bye...');
readln;
end.