disp( This is a game of Rock-Paper-Scissors\') %)Dput player\'s choice players.t
ID: 3694267 • Letter: D
Question
disp( This is a game of Rock-Paper-Scissors') %)Dput player's choice players.turn-input'Make your move (R/P/S):,'s); disp( J if players.turn 'R displ'Player chose Rock') elseif players.turn='P' disel'Player chose Paper') elseif players.turn='s displ'Player chose Scissors') else error 'nvalid input only use R, P or S) end % Create a random number for the computer comouter.turn- randi( 1,3]1) if somputer turn 1 displ'Computer chose Rock) elseif computer turn2 disol'Computer chose Paper') else computer-turn-= 3 displComputer chose Scissors') end %Rules for Rock-Paper-Scissors % Rock beats scissors displPlayer wins' displ'Computer wins') endExplanation / Answer
Add two variables to the code :
ComputerCount = 0;
PlayerCount = 0;
Increase the count variables if the condition is true, then we will get the amount of the game
if(){
/* player Won */
PlayerCount++;
}
if(){
/* computer Won */
ComputerCount++;
}
If User want to quit from the game , the code implementation like following: After displaying winner
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.