title: Game of Pig-java
body: <p>So I made quite a few changes to my code and now it complies, but I get the wrong totals and it always thinks Player 2 wins, even before it hits "20".   For some reason it isn't reading player 1 totalScore until after player 2 has rolled and then it does not calc player 2 turnTotal. When I made changes before, one thing would start working, but another would stop, so I took it back to where I began to have problems once it would compile.</p>
  
  <pre><code> import java.util.*;
  
   public class Proj3Part1
   {
   public static void main(String[] args)
   {
   int turnScore = 0;
   int totalScore = 0;
   int turnScore2 = 0;
   int totalScore2 = 0;
   final int WIN = 20;
   int dice = 0;
   int dice2 = 0;
   String input = "r";
   String input2 = "r";
   char repeat;
  
   Scanner keyboard = new Scanner(System.in);
   Scanner s = new Scanner (System.in);
  
   Random randomNumbers = new Random();
  
   while(totalScore &lt; WIN &amp;&amp; totalScore2 &lt; WIN)
   {
   //Player 1's turn
  
   do
    {
        dice = randomNumbers.nextInt(6) + 1;
        System.out.println();
        System.out.println("You rolled: " + dice);
  
             if(dice == 1)
             {
                 turnScore = 0;
                 System.out.println("Turn over.");
                 System.out.println("Player 1 total is " + totalScore);
                 break;
             }
             else
             {         
                turnScore += dice;
                System.out.print("Player 1 turn total is " + turnScore + " ");
                System.out.print("Enter (r)oll or (s)top: ");
                input = keyboard.nextLine();
                repeat = input.charAt(0);
  
  
           if(repeat == 's')
           {
           System.out.println("Turn over.");
           System.out.print("Current score: Player 1 has " + totalScore);
           System.out.println(", Player 2 has " + totalScore2);
           break;
  
           }
        }
    }
   while(input.equalsIgnoreCase("r") || dice != 1); 
   {             
  
       totalScore += turnScore;
   }
  
    if(totalScore &gt;= WIN)
    {
        System.out.println("Your total Score is " + totalScore);
        System.out.println("Player 1 wins!");
  
    }
  
  
    //player2's turn
    System.out.println();
    System.out.println("It is Player 2's turn.");
  
   { do
    {
        dice2 = randomNumbers.nextInt(6) + 1; 
        System.out.println("Player 2 rolled: " + dice2);
  
        if(dice2 == 1)
          {
            turnScore2 = 0;
            System.out.print("Turn over");
            System.out.println("Player 2 total is " + totalScore2);
            break;             
          }
        else
        {
        turnScore2 += dice2;
        System.out.print("Player 2 total is " +turnScore2 + " ");
        System.out.print("Enter (r)oll or (s)top: ");
        input = keyboard.nextLine();
        repeat = input.charAt(0);
  
  
      if(repeat == 's')
          {
      System.out.println("Turn over");
      System.out.print("Current score: Player 1 has " + totalScore);
      System.out.println(", Player 2 has " + totalScore2);
      break;
          }
      }
  }  
  while(input2.equalsIgnoreCase("r") &amp;&amp; dice != 1); {
  
      totalScore2 += turnScore2;
  
        }
   }
  if(totalScore2 &gt;= WIN);
    {
        System.out.println("Player 2 score is " + totalScore2 + "\n");
        System.out.println("Player 2 wins");
        break;
    }
   }
  
  
  }
  }
  </code></pre>