# Thread: Help with a Dice Game.

1. ## Re: Help with a Dice Game.

An assignment statement uses the = operator. You have about 9 in your program. For example: int snakeEyes=0;

What happens when you execute your program?

2. Member
Join Date
Apr 2012
Location
St. Louis, MO
Posts
32
Rep Power
0

## Re: Help with a Dice Game.

What am I setting equal to each other?

3. ## Re: Help with a Dice Game.

Here is a line from your program that is an assignment:
int snakeEyes=0;

It sets the variable snakeEyes to 0

4. Member
Join Date
Apr 2012
Location
St. Louis, MO
Posts
32
Rep Power
0

## Re: Help with a Dice Game.

I understand what an assignment is now, but I'm not sure what you're asking me to assign values to

5. ## Re: Help with a Dice Game.

Go back to posts 15 and 16 that discussed the logic of your code.

6. Member
Join Date
Apr 2012
Location
St. Louis, MO
Posts
32
Rep Power
0

## Re: Help with a Dice Game.

Infinite loop of "snakeyes" and "doubles".

Java Code:
```while(contin)
{
int num1=dieA.roll();
int num2=dieB.roll();
int sum=num1+num2;

if(num1==1 && num2==1)
{
snakeEyes++;
System.out.println("You have rolled snake eyes");

if(num1==num2)
{
System.out.println("You have rolled doubles");

}
if(sum==GOAL)
{
System.out.println("Matched goal of "+GOAL);
contin=false;

}

}```

7. ## Re: Help with a Dice Game.

Add some println statements inside the loop to print out the values of sum, num1 and num2 so you can see what the code is doing.

8. Member
Join Date
Apr 2012
Location
St. Louis, MO
Posts
32
Rep Power
0

## Re: Help with a Dice Game.

Originally Posted by Norm
Add some println statements inside the loop to print out the values of sum, num1 and num2 so you can see what the code is doing.

Just took a SS of the infinite loop.

9. ## Re: Help with a Dice Game.

Which is num1 and num2 and sum?
What is the value of GOAL?

When will contin be set false? What do the values of num1 and num2 and GOAL have to be for contin to be set = false?

Can you post the full code. What you posted in post#26 does not show the full logic of your code.
Also the formatting is not done correctly so it is hard to understand the logic.

10. Member
Join Date
Apr 2012
Location
St. Louis, MO
Posts
32
Rep Power
0

## Re: Help with a Dice Game.

Java Code:
```import cs1.Keyboard;
public class DieGame
{
public static void main (String[] args)
{

int snakeEyes=0;
Die dieA=new Die();
Die dieB=new Die();
boolean contin=true;
if(GOAL<=2||GOAL>12)
{
System.out.println("INVALID NUMBERS");
}
else
{

while(contin)
{
int num1=dieA.roll();
int num2=dieB.roll();
int sum=num1+num2;
System.out.println(num1);
System.out.println(num2);

if(num1==1 && num2==1)
{
snakeEyes++;
System.out.println("You have rolled snake eyes");

if(num1==num2)
{
System.out.println("You have rolled doubles");

}
if(sum==GOAL)
{
System.out.println("Matched goal of "+GOAL);
contin=false;

}

}

}

}
}

}```
I apologize about the formatting/brackets. Not sure how to arrange them properly
Last edited by HalfAZN; 04-30-2012 at 06:32 PM. Reason: Grammar

11. ## Re: Help with a Dice Game.

You need to properly format the code so that the {}s and indentations show nesting logic. Especially lines 40 to 54.

The printlns should include an ID String so you know where it was printed. For example:
System.out.println("num1="+num1);

A list of numbers is not useful if you can not tell which is which.
Last edited by Norm; 04-30-2012 at 06:39 PM.

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•