Created
September 26, 2019 18:24
-
-
Save matteing/f2423a909fb0ce182938feb05a29255e to your computer and use it in GitHub Desktop.
stick 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
#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