# Write a method calles diceSum

Sora McKain
Greenhorn
Posts: 4
Hi, I am having a little trouble understanding why I am not getting this right, I followed all the steps in the book and it still came out wrong, help please!

Write a method called diceSum that accepts a Scanner for the console as a parameter and prompts for a desired sum, then repeatedly simulates the rolling of 2 six-sided dice until their sum is the desired sum. Here is a sample dialogue with the user:

Desired dice sum: 9

4 and 3 = 7

3 and 5 = 8

5 and 6 = 11

5 and 6 = 11

1 and 5 = 6

6 and 3 = 9

So what am i not understanding?

Jeff Verdegan
Bartender
Posts: 6109
6
Hi, and welcome to the Ranch!

Folks here will be better able to help you if you TellTheDetails(←click) about exactly what's not working for you or what you're not understanding.

Jeff Verdegan
Bartender
Posts: 6109
6
Off the bat, though, I will ask you to explain exactly why you put this line in and what you think it will do:

William P O'Sullivan
Ranch Hand
Posts: 859
You never read the desired result (i.e: 9 from the scanner).

You have hardcoded the "desired result" of 7 at line 11.

WP

Kemal Sokolovic
Bartender
Posts: 825
5
Here is a sample dialogue with the user:
...

It's certainly not from the code you posted, since that one can't even be compiled.

Sora McKain
Greenhorn
Posts: 4
Jeff Verdegan wrote:Off the bat, though, I will ask you to explain exactly why you put this line in and what you think it will do:

Well I get an error that says

Dice.java:6: illegal start of expression
r.nextInt=();
^
1 error

so thought I might need that line but it obviously does no good.

Jeff Verdegan
Bartender
Posts: 6109
6
That sounds like Programming By Accident. Not a particularly effective approach.

It's okay to guess sometimes, but if you do, make sure you at least have some expectation of what each piece means and why it might work.

So, for instance, when you write

don't just do it because you're sticking arbitrary symbols together. If you have a theory as to what each piece of that line might mean, and why you might need it, then sure, try it out, see if your theory holds up. But just reaching into the blind grab bag and throwing together whatever happens to come out--an - sign here, some parentheses there--is something to be avoided always.

Sora McKain
Greenhorn
Posts: 4
Thanks to all for your help, I have figured out my problem (I also figured out that this is not something I should be doing on little to no sleep lol).

Once again thank you. If I have problems in the future I will be sure to ask.