MedVision ad

What's the correct way to receive function value in psuedocode?? (1 Viewer)

mAtboisLim

Member
Joined
Jan 9, 2004
Messages
55
Location
Sydney
Gender
Male
HSC
2005
I'm confussed about how to return values from a function, using psuedocode, because it isn't really defined anywhere by the Board of Studies.

Is the following, shorter method okay:

Code:
BEGIN MAINPROGRAM

[U]GetAnswer[/U] (Value1, Value2)

Print Answer 
Print Answer2

END MAIN PROGRAM 

BEGIN [U]GetAnswer[/U] (Value1, Value2)

....(some processing)

Return Answer, Answer2
END [U]Get Answer[/U]
OR do you have to create another variable in the mainline (e.g answers below), to store the return value of the function:

Code:
BEGIN MAINPROGRAM

[B]Answers = [/B] [U]GetAnswer[/U] (Value1, Value2)

Print Answers.Answer1
Print Answers.Answer2

END MAIN PROGRAM 

BEGIN [U]GetAnswer[/U] (Value1, Value2)

....(some processing)

Answers.Answer1 =  (some value)
Answers.Answer2 = (some value) 

Return Answers
END [U]Get Answer[/U]
 
Last edited:
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
depends on the case scenario, some questions tell you you "and show the value to be returned to the user", if thats the case i'd set it to a variable

btw be careful how you use answers.Answer1 etc.., you indicate that its an array (of records?), and if it isnt and you put that, maybe they can bust your balls?
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
most the time they dont even ask to say "and return the value to the user", but sometimes they do, id be cautious, but otherwise most the time the first one usually is fine
 

mAtboisLim

Member
Joined
Jan 9, 2004
Messages
55
Location
Sydney
Gender
Male
HSC
2005
Disregarding the 'print' part ('return the value to the user'), if I wanted to use the values returned by the function GetAnswer, in the main line, is the first way okay?
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
umm im not 100% sure about that, you are declaring answers to get its value from a subprogram, but if you notice there are several variables that actually get answer spits out

BEGIN GetAnswer (Value1, Value2)

....(some processing)

Answers.Answer1 = (some value)
Answers.Answer2 = (some value)

Return Answers
END Get Answer

I mean what is answers declared to, Answers? Answers.Answer1 ? Answers.Answer2?

i know what you mean, i know its meant to be answers, and the marker probably would, but you have to make it clear :uhhuh:
 

mAtboisLim

Member
Joined
Jan 9, 2004
Messages
55
Location
Sydney
Gender
Male
HSC
2005
I think the second way is preety clear.

But I was asking about the first way. Do you need to assign a variable in the main line to receive the return values of a called function?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top