Answer
- The first line contains the keyword ``FUNCTION'' instead of
``PROGRAM.'' A program can contain any number of function
definitions, but it must contain exactly one main program.
- The type of the value returned by the function is indicated on the
first line. This is not necessary in a main program, which does not
return values.
- The names of the parameters are indicated in parentheses in the
first line, and their types are given a few lines further down. This
is not necessary in a main program, which does not take parameters.
- A variable with the same name and type as the function can be assigned a
value in the body of the function.
- The keyword ``RETURN'' is used in place of ``STOP''. We do not
want a program to stop execution when a function is finished; instead,
we want the value computed by the function to be returned to the
caller.
Return to lesson.
Hamlet Project
hamlet@cs.utah.edu