go to previous page   go to home page   go to next page hear noise highlighting

Answer:

Yes, but this would add more logic to the program. You might want to do this as an exercise.


Determining the Winner of the Round

The final code in the loop body determines the winner of the round:


// Determine Winner of Round and Adjust Scores
if ( playerToss > compToss )
{
  playerScore = playerScore+1;
  System.out.println("You win the round!");
}
else
{
  compScore = compScore+1;
  System.out.println("You loose the round!");
}      
System.out.println("Score: computer " + compScore + ", you " + playerScore + "\n");

There is nothing difficult here, but notice that the code is written so that the computer wins when the dice tosses are equal.


QUESTION 22:

As another exercise, you could add code to do something else when the tosses are equal.


go to previous page   go to home page   go to next page