Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
This function should return the larger of two integers, and the main program should output twice the larger value.
FUNCTION Bigger(First : INTEGER, Second : INTEGER) RETURNS INTEGER
IF First > Second
THEN
OUTPUT First
ELSE
OUTPUT Second
ENDIF
ENDFUNCTION
CALL Bigger(12, 19)Identify the errors and write a corrected version. What does your version output?
A maintainable program uses meaningful identifiers, comments, constants for values that may change, and procedures and functions for separate jobs. In the 15-mark scenario question, list every task, plan the data, write the program in commented parts, and dry-run it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
The errors.
RETURN.CALL Bigger(12, 19) treats the function as a procedure. A function is used inside an expression, without CALL.The corrected version.
FUNCTION Bigger(First : INTEGER, Second : INTEGER) RETURNS INTEGER
IF First > Second
THEN
RETURN First
ELSE
RETURN Second
ENDIF
ENDFUNCTION
OUTPUT Bigger(12, 19) * 2The output. Bigger(12, 19) returns 19, and . The output is 38.
Log in to join the discussion.
Loading…