I am trying to implement a nim game where the computer and a player take turns in removing marbles from a pile, the last one to take a marble loses. I came across this problem. I am using an evaluate fuction to determine whether the user inputs a number inside the desired interval(1,pile/2). I does not work correctly though. The program will subtract the marble inputed by the user whether it is inside the interval or not.
using namespace std;
int pile = 20;
bool evaluate(int x);
cout << "Pile is set to " << pile << endl;
cout << "Your turn";
cin >> humanMarbles;
if (evaluate(humanMarbles) == true);
pile = pile - humanMarbles;
cout << "Pile is set to " << pile;
cout << "This is a Nim Game implementation \n"
"you play against the computer taking turns removing marbles from a marble pile \n"
"you may take 1 up to pile/2. The one who takes the last marble loses \n";
cout << endl << endl;
//pile = rand() % 100 + 1;
bool evaluate(int x)
if (x <= pile/2 && x>=1)
check = true;
cout << "Cannot take marbles";
check = false;
Also the lines highlighted as comment cause a compiler error in a platform different than dev c++. Implicit declaration of fiction...What is that about?!