# Help with a Dice Game.

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 04-26-2012, 05:40 PM
Norm
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?
• 04-27-2012, 05:10 PM
HalfAZN
Re: Help with a Dice Game.
What am I setting equal to each other?
• 04-27-2012, 05:12 PM
Norm
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
• 04-27-2012, 05:25 PM
HalfAZN
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
• 04-27-2012, 05:30 PM
Norm
Re: Help with a Dice Game.
Go back to posts 15 and 16 that discussed the logic of your code.
• 04-27-2012, 05:45 PM
HalfAZN
Re: Help with a Dice Game.
Attachment 3650

Infinite loop of "snakeyes" and "doubles".

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;                                 } }```
• 04-27-2012, 05:50 PM
Norm
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.
• 04-30-2012, 05:07 PM
HalfAZN
Re: Help with a Dice Game.
Quote:

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.

Attachment 3718

Just took a SS of the infinite loop.
• 04-30-2012, 05:13 PM
Norm
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.
• 04-30-2012, 06:31 PM
HalfAZN
Re: Help with a Dice Game.
Code:

```import cs1.Keyboard; public class DieGame {     public static void main (String[] args)     { System.out.println("Please enter a GOAL number");         int GOAL=Keyboard.readInt(); 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
• 04-30-2012, 06:36 PM
Norm
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.
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12