139k 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.

User Yawl
by
6.1k points

1 Answer

1 vote

Answer:

if(score1 > score2)

{

cout<<"player1 wins"<<endl;

player1Wins++;

player2Losses++;

}

elseif(score1<score2)

{

cout<<"player2 wins"<<endl;

player2Wins++;

player1Losses++;

}

else

{

cout<<"tie"<<endl;

tieCount++;

}

Step-by-step explanation:

The above written statement is in C++.I have used if-elseif ladder to meet the requirements for the question and the variables are increased according to the win and loss of the respective players and also for the case of tie.I have used post increment operator to increase the count.

User Khara
by
6.1k points