RECORDS AND PROCEDURES
The following program demonstrates passing a record to a
procedure, which updates the record, then prints the updated
time.
program TIME (input,output);
type time = record
seconds, minutes, hours : integer
end;
var current, next : time;
{ function to update time by one second }
procedure timeupdate( var now : time); {variable parameter}
var newtime : time; {local variable}
begin
newtime := now; {use local instead of orginal}
newtime.seconds := newtime.seconds + 1;
if newtime.seconds = 60 then
begin
newtime.seconds := 0;
newtime.minutes := newtime.minutes + 1;
if newtime.minutes = 60 then
begin
newtime.minutes := 0;
newtime.hours := newtime.hours + 1;
if newtime.hours = 24 then
newtime.hours := 0
end
end;
writeln('The updated time is ',newtime.hours,':',newtime.minutes,
':',newtime.seconds)
end;
begin
writeln('Please enter in the time using hh mm ss');
readln( current.hours, current.minutes, current.seconds );
timeupdate( current )
end.