So below is my nim game. Basically pick up sticks...
my problem is that when the "pile" gets low, even if you enter less than the last remaining pile size the cout message "That is more sticks than is remain in the pile!" pops up??
if you run and play it in VS command prompt you'll see what I mean.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
// Initial variable declaration.
int pile = 13;
int p1Sticks;
int p2Sticks;
int curPile = pile;
string player1;
string player2;
//Welcome message and rules.
cout << "\t\t\t~Welcome to Nim!~" << endl << endl;
cout << "\tThe object of the game is to be the player to pick up the last stick" << endl;
cout << "\t\tYou may pick up between 1 and 4 sticks per turn." << endl;
cout << "\tRemember the first to be the last wins so play with a strategy!" << endl << endl;
// Enter Player names.
cout << "Player one please enter your name: ";
cin >> player1;
cout << endl << endl;
cout << "Player two please enter your name: ";
cin >> player2;
cout << endl << endl;
cout << "Thank you " << player1 << " and " << player2 << "!" << endl << endl;
//Do-While loop for sticks remaining in pile.
do
{
//Do-While loop for each player one turn.
do
{
cout << player1 << " how many sticks would you like to pick up? ";
cin >> p1Sticks;
curPile = (curPile - p1Sticks);
//if conditions for game parameters player 1.
if (p1Sticks < 1){
cout << "You must opt to pick up at least one stick!" << endl;}
if (p1Sticks > 4){
cout << "Four is the maximum amount of sticks per turn!" << endl;}
if (curPile < p1Sticks){
cout << "That is more sticks than is remain in the pile!" << endl;}
if (curPile ==0){
cout << player1 << " You win! Congratulations!" << endl << endl;
return 103;
}
else{
cout << "There are " << curPile << " sticks remaining " << player1 << "!" << endl << endl;
break;
}
}while (curPile != 0);
//Do-While loop for each player two turn.
do
{
cout << player2 << " how many sticks would you like to pick up? ";
cin >> p2Sticks;
curPile = (curPile - p2Sticks);
//if conditions for game parameters player 2.
if (p2Sticks < 1){
cout << "You must opt to pick up at least one stick!" << endl;}
if (p2Sticks > 4){
cout << "Four is the maximum amount of sticks per turn!" << endl;}
if (curPile < p2Sticks){
cout << "That is more sticks than is remain in the pile!" << endl;}
if (curPile ==0){
cout << player2 << " You win! Congratulations!" << endl << endl;
return 103;
}
else {
cout << "There are " << curPile << " sticks remaining " << player2 <<"!" << endl << endl;
break;
}
}while (curPile != 0);
}while (curPile != 0);
cout << "Play Again!";
return 0;
}