0

I have this command Out.print(getWin(dice, bet, bid)); but Java doesn't seem to know the 3 values dice, bet and bid as they are return values of other methods and therefore not known in the Main Method.

Now I know that there is the possibility to call up the whole functions to give the return values as parameters Out.print(getWin(rollTheDice(), givenBet(), givenBid())); but the big problem is that the exercise I am working on, requires me to include lines like System.Out.Print("Amount of Bid: "); into the functions itself which means that when I call up the functions as parameters it starts printing out code and asking the user to enter data again and I am trapped in an endless loop instead of getting the return value of the function getWin which is the thing I actually want.

Is there any way I can pass on the parameters as variables like suggested in the 1st row of the question? Maybe by initializing them outside the function (although I already tried that as well and it didn't work either)? Otherwise I am starting to think this exercise isn't really doable the way I am supposed to do it.

Dave Twickenham
  • 171
  • 1
  • 8
  • Giving an exact answer is kind of hard without seeing your code. In general you can use the return value as a method parameter in the same way as you can use any variable. You just need to assign the return value to a variable of your choice, like `String stringReturnValue = someMehtodThatReturnsString();` and then you can use that variable when calling methods eG `callSomeOtherMethod(stringReturnValue);`. – OH GOD SPIDERS Nov 11 '21 at 15:52
  • @OHGODSPIDERS but where do I have to assign the return value? If I do it in the method itself then it's not visible in the main method and therefore not usable. They are `int` btw but that's not important. – Dave Twickenham Nov 11 '21 at 15:57
  • I don't know anything about your code so how am I supposed to tell you where exactly it would make sense in your code to call methods and pass return values around? Maybe [What is 'scope' in Java?](https://stackoverflow.com/questions/38177140/what-is-scope-in-java) will help you. – OH GOD SPIDERS Nov 11 '21 at 16:01

1 Answers1

2

I was able to fix it:

The clue is to assign the functions to variables as the commenter suggested and at the same time executing the function:

int dice = rollTheDice();
int bet = givenBet();
int bid = givenBid();
getWin(dice, bet, bid);
Dave Twickenham
  • 171
  • 1
  • 8