Last active
August 29, 2015 14:18
-
-
Save rbtr/fe83f554b989b9efaf82 to your computer and use it in GitHub Desktop.
MATLAB code for a 2 player count to 10 game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc | |
sum = 0; | |
player = 1; | |
while (sum < 10) | |
choice = -1; | |
fprintf('Player %i\n', player); | |
while (~(choice == 1 || choice == 2)) | |
choice = input('Enter 1 or 2: '); | |
end | |
sum = sum + choice; | |
player = 2 / player; | |
end | |
fprintf('Player %i wins!\n', player); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment