17 Oct
17Oct


This program is about the toothpick game.In which there are 23 toothpicks at the start of game.Players pick toothpicks from the pile are either only 1 or 2 or 3.First pick is from user and the other one is from computer.The player who pick the last one toothpick will be a  loser.

#include 
using namespace std;

int main()
{
cout << "\t\tWelcome to the toothpick game!\n";
int num = 0, computerPick = 0, humanPick = 0, toothpick = 23;
bool flag = NULL;

while (humanPick != 4)
{
cout << "\nPlease pick up your toothpick(s), choose between 1 and 3 : ";
cin >> humanPick;

if (humanPick > 3 || humanPick < 0 || !humanPick || humanPick>toothpick)
{
cout << "\nPlease enter a correct value!\n";
cout << toothpick << " toothpick(s) remaining\n" << endl;
humanPick = 0;
}
else
{
toothpick -= humanPick;
flag = false;

if (toothpick <= 0)
cout << "\n\tComputer has Prevailed!";
else
{
if (toothpick > 4)
computerPick = 4 - humanPick;
else if (toothpick == 1)
computerPick = 1;
else if ((toothpick >= 2) || (toothpick <= 4))
computerPick = toothpick - 1;
cout << "The computer took " << computerPick << " toothpick(s)" << endl;

toothpick -= computerPick;
flag = true;

if (toothpick <= 0)
cout << "\n\tYou have Prevailed!";
else
{
cout << toothpick << " toothpick(s) remaining" << endl;
}
}
if (toothpick <= 0)
{
cout << "\n\nEnter any integer except 4 to Play agin\nEnter 4 to exit\n\n\tEnter your choice : ";
cin >> humanPick;
toothpick = 23;
}
}
}
cout << "\n\n\n";
system("pause");
return 0;
}

Click on the below link to download the executable file of 23 Toothpicks Game.

23 Toothpick Game.zip

Comments
* The email will not be published on the website.
I BUILT MY SITE FOR FREE USING