[Logo]
Forums Register Login
basics: return value to main
I would like to use return to pass a value from one method call to the next in main. Tried to find something about this in a couple books with as yet no success...
What happens to a value that gets returned from a method? How can I lassoe it for the next method call?
Thanks for your help once again,
Pauline

Dont know which one our nitpicker prefers .
Hi jdj, thanks for the tips. I had actually tried those 2 options, but the methods hadn't been declared as private. That's my next step. What's the reason behing the "privacy" of the method?
(Guess I could look it up in a book somewhere, but that'd be less fun...)

Pauline
Still trying, no success yet.
Tried with private method but I'm still getting a compiler error that the method isn't found. My case is slightly different, I'm trying to pass the return value of a method to the second call of the same method, but with different parameters.

Is this a special case or am I greener than green today?
cheers,
Pauline

[This message has been edited by Pauline McNamara (edited May 18, 2001).]
Pauline, the thing I see is that in your method calls you don't have int j = methodDoSomething(xxx,xxx,xxx). So your returnValue has nowhere to go.
rick

Originally posted by Pauline McNamara:
[B]Still trying, no success yet.
Tried with private method but I'm still getting a compiler error that the method isn't found. My case is slightly different, I'm trying to pass the return value of a method to the second call of the same method, but with different parameters.

Is this a special case or am I greener than green today?
cheers,
Pauline

[This message has been edited by Pauline McNamara (edited May 18, 2001).][/B]

Specifically for your code , replace:
methodDoSomething( thisParam , thatParam , anotherParam ) ;
with:
int returnValueOfFirstDoSomethingCall = methodDoSomething( thisParam , thatParam , anotherParam ) ;
Paul R
[This message has been edited by Paul Ralph (edited May 18, 2001).]
Thanks folks. I got the return value where I wanted it, finally. Progress in baby steps.
Here's another sticky detail: my method DoSomething also prints out stuff. When I put in a line like you suggested to get the return value:
...
methodDoSomething( thisParam , thatParam , anotherParam ) ;
int i = methodDoSomething( thisParam , thatParam , anotherParam ) ;
methodDoSomething( i, blah, bloo ) ;
...
the method seems to get called on the first AND second line too so the stuff gets printed out twice (correctly, but twice).
Maybe I'm trying to go down the wrong road?
Really appreciate your input.
cheers,
Pauline
I finally got it. Thanks you guys. And thank you Marilyn: one harmless looking little nitpick and I got a lesson in combining value assignment with the method call, mixed in with a brush-up on precedence.
In the end (or rather, for the latest submission of this assignment), the method call looks like you suggested, Paul:
........
variablePassedAsParam = methodDoSomething( variablePassedAsParam, anotherParam, yetAnotherParam ) ;
methodDoSomething( variablePassedAsParam, anotherParam, yetAnotherParam ) ;
..........
If I've understood correctly, the method call gets evaluated first, prints out its stuff and returns a value for assignment to the variable, which then gets used in the next call of the method.
Ho Doggie.
To my inexperienced eye it makes main look a lot less simple... anyway, I can submit it and go out and play now.
Why do I see/feel/think recursion when I look at this?


Originally posted by Pauline McNamara:
variablePassedAsParam = methodDoSomething( variablePassedAsParam, anotherParam, yetAnotherParam ) ;
methodDoSomething( variablePassedAsParam, anotherParam, yetAnotherParam ) ;

I'm sorry I can't help it
[This message has been edited by Richard Boren (edited May 19, 2001).]
Hi Richard, yes it should even smell like recursion because it's what used to be a loop. Since it's loop days, though, it went through the same considerations/nitpicks as those brought up by Paul R in the Say 4b technique thread.
I couldn't help thinking loop either, but now I'm getting help to think differently...

Pauline
Boy I almost wrote a really stupid reply to your last post. I'm glade I re-read it before I clicked the submit button. I thought you were calling it a loop
Thanks for clearifying that for me.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 16, 2017 15:42:15.