I have two questions with my code. I am writing a program that simulates a game of Rock, Paper, Scissors played between two users. The winner is determined by the best of five computer generated rounds.
Three requirements:
- You must write a loop to run the five rounds of the game, assigning the values into two arrays, allowing no ties.
- You must write a loop to determine the number of wins for each player.
- You must write a loop to print the values in each array (mapped to words).
I need help with the "allowing no ties" in the first requirement and mapping words to the values in the array to print in the third requirement.
So, I need these arrays:
Player 1 1 0 1 2 2
Player 2 2 1 0 1 0
to look like this:
Player 1 Player 2
paper scissors
rock paper
paper rock
scissors paper
scissors rock
Here is my first loop:
for(index=0; index<5; index++){
player1[index]=random.nextInt(3);
player2[index]=random.nextInt(3);
Second loop:
for(index=0; index<5; index++){
if((player1[index]==0) && (player2[index]==2)){
player1Win++;
}else if((player1[index]==1) && (player2[index]==0)){
player1Win++;
}else if((player1[index]==2) && (player2[index]==1)){
player1Win++;
}else{
player2Win++;
}
}
Third loop:
for(index=0; index<5; index++){
System.out.print("\t\t " + player1[index] + "");
System.out.println("\t " + player2[index] + "");
}
Thank you!
player1[index]=random.nextInt(3);
is populating you arrays with integers.if((player1[index]=='0') && (player2[index]=='2')){
is comparing yours arrays as if they contain characters.Try
if((player1[index]==0) && (player2[index]==2)){
etc (just remove the single quotes).