var
reference_date,current_date,birthday:date;
cont:char;
continue:boolean;
function age (current_date,birthday:date):real;
var
days_elapse_from_birth_to_current_date,years,days,months:integer;
years_of_age:byte;
months_of_age:real;
days_from_reference_to_current_date,days_birthday_to_reference:integer;
function elapse_time(date_to_use:date):integer; {internal function}
var
pastdays:byte;
begin
years:=0;
days:=0;
years:= (date_to_use.year - reference_date.year);
days:= days + date_to_use.day + (years div 4); {+ days so far in month
and correct for leap years}
days:= days + (years*365); {now add in days of years gone by}
{days should now = total days from date of test to reference year }
elapse_time:=days;
end; {of internal procedure elapse time}
begin { of function age}
years_of_age:=0;
months_of_age:=0;
while continue do
begin
writeln(chr(27),'[2J',chr(27),'[1;1H'); {clear screen}
writeln('Calculate the age of a patient given birth and current date.');
write('Enter current date as mm, dd, yy ');
readln(current_date.month, current_date.day, current_date.year);
writeln;
write('Enter date of birth as mm, dd, yy ');
readln(birthday.month, birthday.day, birthday.year);
writeln;
writeln;
writeln('Age is : ',age(current_date,birthday):2:2, ' years');
readln(cont);
if cont = chr(27) then continue:= false;
end; {of while}
end.