6.1k views
1 vote
Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2, the message "player1 wins" is printed to standard out. When score2 exceeds score1, the message "player2 wins" is printed to standard out. In each case, the variables player1Wins, player1Losses, player2Wins, and player2Losses, are incremented when appropriate. Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented.

1 Answer

6 votes

Answer:

Following are the statement in the C++ Programming Language.

//check condition that score1 is greater than score2

if (score1 > score2)

{//print the message and brake line

cout << "player1 wins" << endl;

//increment in the variable by 1

++player1Wins;

//increment in the variable by 1

++player2Losses;

}

//check condition when score2 is greater than score1

else if (score2 > score1)

{ //print the message and brake line

cout << "player2 wins" << endl;

//increment in the variable by 1

++player2Wins;

//increment in the variable by 1

++player1Losses;

}

//otherwise

else

{ //print the message and brake line

cout << "tie" << endl;

//increment in the variable by 1

++tieCount;

}

Step-by-step explanation:

Following are the description of the program.

  • In the statement, we check that the variable 'score1' is greater than 'score2' then, print message and brake line, then increment in the variables by 1 that is 'player1Wins' and 'player2Losses'.
  • Again check that the variable 'score2' is greater than 'score1' then, print message and brake line, then increment in the variables by 1 that is 'player2Wins' and 'player1Losses'.
  • Otherwise, print the following message and break line then, increment in the variable 'tieCount'
User Mjmuk
by
5.0k points