Rock, Paper, Scissors in MATLAB?
23 views (last 30 days)
Show older comments
Brian Tiffman
on 12 Nov 2015
Commented: Brian Tiffman
on 13 Nov 2015
In the attached document, looking at problem 4, how would I write the code using a matrix and while loop. I know how to write the code using many if statements, but I want some insight on how to use the matrix I created in a while loop. Im just looking for help, and not the answer given to me for my problem. Any help would be greatly appreciated. Thanks!
0 Comments
Accepted Answer
Image Analyst
on 12 Nov 2015
Here's a hint/snippet
gamesPlayed = 0
while gamesPlayed < 100 % Or whatever max you reasonably expect
% Other Code: menu(), randi(), etc.
% Increment the number of games played
gamesPlayed = gamesPlayed + 1;
promptMessage = sprintf('Do you want to Continue playing,\nor Quit?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if strcmpi(button, 'Quit')
break;
end
end
3 Comments
Image Analyst
on 12 Nov 2015
Your code has to get the computer and your choice. Then use those as rows and columns into the matrix to decide if you won, the computer won, or it was a tie. Then increment the wins and losses and ties for you and the computer.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!