The purpose of the code is to have 2 players roll a pair of dice. The first player to roll a total of 20 wins the game. I'm having trouble figuring out how to properly track the sum of the rolls; it only gives me the sum of that current turn, and then the game ends when each player rolled 10 times.
How do I properly count the sum of each players game, and then stop the loop when one of the players' sums is equal to 20?
int a, b, c, d;
int playerone=0, playertwo=0;
Random gen = new Random();
a=gen.nextInt(6)+1;
b=gen.nextInt(6)+1;
c=gen.nextInt(6)+1;
d=gen.nextInt(6)+1;
while(playerone!=20 || playertwo!=20) {
playerone=a+b;
playertwo=c+d;
System.out.println("Player 1 rolled " + a + " and a " + b );
System.out.println("Player 1 now has " + playerone);
System.out.println("Player 2 rolled " + c + " and a " + d );
System.out.println("Player 2 now has " + playertwo);
a=gen.nextInt(6)+1;
b=gen.nextInt(6)+1;
c=gen.nextInt(6)+1;
d=gen.nextInt(6)+1;
playertwo+=a+b;
playerone+=c+d;
if(playerone==20)
System.out.println("player one wins ");
else if (playertwo==20)
System.out.println("player two wins ");
}
}