Page 2 of 2 FirstFirst 12
Results 21 to 31 of 31
Like Tree1Likes

Thread: Help with a Dice Game.

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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?
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Default Re: Help with a Dice Game.

    What am I setting equal to each other?

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Default 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. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Help with a Dice Game.

    Go back to posts 15 and 16 that discussed the logic of your code.
    If you don't understand my response, don't ignore it, ask a question.

  6. #26
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Default Re: Help with a Dice Game.

    Help with a Dice Game.-infi.png

    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. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  8. #28
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Default Re: Help with a Dice Game.

    Quote Originally Posted by Norm View Post
    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.
    Help with a Dice Game.-sup.png

    Just took a SS of the infinite loop.

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  10. #30
    HalfAZN is offline Member
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    32
    Rep Power
    0

    Default Re: Help with a Dice Game.

    Java 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
    Last edited by HalfAZN; 04-30-2012 at 06:32 PM. Reason: Grammar

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Pig dice game
    By dangyounoobs in forum New To Java
    Replies: 2
    Last Post: 12-09-2013, 04:21 AM
  2. Dice Game
    By Rachel1991 in forum New To Java
    Replies: 1
    Last Post: 11-24-2011, 11:10 PM
  3. Pig Dice Game Help
    By pvccstudent in forum New To Java
    Replies: 3
    Last Post: 07-10-2011, 02:21 AM
  4. Need help with AI in roll dice game
    By shazakala in forum New To Java
    Replies: 3
    Last Post: 04-04-2011, 11:49 AM
  5. Help with a dice game.
    By hero in forum AWT / Swing
    Replies: 14
    Last Post: 07-26-2009, 11:50 AM

Posting Permissions

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