Skip to content

Instantly share code, notes, and snippets.

@rbtr
Last active August 29, 2015 14:18
Show Gist options
  • Save rbtr/fe83f554b989b9efaf82 to your computer and use it in GitHub Desktop.
Save rbtr/fe83f554b989b9efaf82 to your computer and use it in GitHub Desktop.
MATLAB code for a 2 player count to 10 game.
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