Skip to content

Instantly share code, notes, and snippets.

@matteing
Created September 26, 2019 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteing/f2423a909fb0ce182938feb05a29255e to your computer and use it in GitHub Desktop.
Save matteing/f2423a909fb0ce182938feb05a29255e to your computer and use it in GitHub Desktop.
stick game
#include <iostream>
using namespace std;
int main()
{
int player = 1;
int sticks = 1;
int selection;
do {
cout << "Input a number of sticks [10, 100]: ";
cin >> sticks;
cout << endl;
} while (sticks < 10 || sticks > 100);
while (sticks > 0) {
player = player == 1 ? 2 : 1;
cout << "There are " << sticks << " remaining." << endl;
do {
cout << "Player " << player << ", enter a number of sticks to take [1, 3]: ";
cin >> selection;
} while (selection > 3 || selection < 0);
sticks -= selection;
}
cout << "The loser was player " << player << "." << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment