05-04 SUBROUTINES - Algorithm 4
05-04 SUBROUTINES - Algorithm 4
Question Answer
Question Answer
A programmer has been asked to write a function which will receive ***There are always different ways to solve a problem. This algorithm is
the age of a user (e.g. 15) and calculate their age in 50 years, just an example. What is important is that the logic is correct!***
returning the result back to the main program for outputting.
LOGIC:
Write a subroutine, in pseudocode, which shows the logic of the
problem above. •Declare a function with a parameter
•Add 50 to the parameter value and store the result
•Return the result back to the main program
•Call the function passing 15 as an argument, ensuring the function is
assigned to a variable which will receive the returned value.
•Output the returned value.
EXAMPLE ALGORITHM:
function ageInFifty(x)
answer = x + 50
return answer
endfunction
result = ageInFifty(15)
print(result)