Explore BrainMass

Reference parameter variable

Design a module named getNumber which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.

I'm having difficulty comprehending the concept of a reference variable. I've written my module below, however I'm unsure if I'm correct. I respectfully request your review and suggestions.

Module main ()
//Declare and initialize variable
Declare Integer = 99
//Display the value in variable
Display "x is set to", x

//Pass variable to getNumber
Call getNumber (x)

//Display the values now
Display "Enter a number"
Input number
Display "x is set to", x
End Module

Module getNumber (Integer Ref value)
Set value = 0
End Module

Solution Preview

Following is how your module code should look like to address the given problem.

Module main ()

// Declare and initialize variable
Declare Integer x = 99

// Display the value in variable

Solution Summary

Solution also gives a corresponding C++ implementation to see the reference variable in action.