Adding player 2 to Nim

Hey! This is my code so far and it works fine but Player 2 cannot win only Player 1. Anyone know how to fix this!








#include <iostream>
#include <string>
using namespace std;
int main()
{
const int total = 13;
int n, mtotal;
bool winner = false;

mtotal = total;

while (!winner)
{
if (mtotal >= 0)
cout << "There are " << mtotal << " sticks" << endl;
cout << "Player 1, pick a number between 1 and 4" << endl;
cin >> n;
if (n >= 1 && n <= 4)
{
cout << "You have removed " << n << " stick(s)" << endl;
mtotal -= n;
}
else
{
cout << " Invalid number" << endl;
}
{
if (mtotal >= 0)
cout << "There are " << mtotal << "sticks" << endl;
cout << "Player 2, pick a number between 1 and 4" << endl;
cin >> n;
if (n >= 1 && n <= 4)
{
cout << "You have removed " << n << " stick(s)" << endl;
mtotal -= n;
}
else
{
cout << " Invalid number " << endl;
}
}

if (mtotal <= 0)
{
winner = true;
cout << " Player 1 wins" << endl;
}

}

system("pause");
}
Without giving any code because I'm at work, your code needs to store mtotal for each indvidual player, then check both mtotals at the end for mtotalPlayer1 <= 0 then player1 win else if mtotalPlayer2 <= 0 player2 win
Topic archived. No new replies allowed.