Creating a loop for Two player game

Hello everyone!!

I need a lil help trying to figure out how to loop two players of a chip game.
Im new to c++ and I'm trying to understand this stuff the best I can and I hit a wall. Just need a lil push.

this is what I got
current = player1;

while (totalChips>=0)
{
maxChips=totalChips/2;
if (totalChips%2==1)
{
maxChips+=1;
}

cout << endl << current << " how many of the remaining " << totalChips << " chip(s) would you like ("<<maxChips<< " max): ";
cin >> currentChips;

if(currentChips>=maxChips)
{
cout << " Sorry, please try again.";
}
else (maxChips>=currentChips);
{
current = player2;
}
totalChips=totalChips-currentChips;
}
1
2
3
for (int i = 0; i < numberOfPlayers; ++i) {
 // Do stuff for each player
}
Last edited on
Alright I got it to work from going to player one to chose his chips, but once it goes to player 2 it gets stuck on player 2. How do I get it two alternate?
Are you using classes and OOD?
Just a thought, but a circularly linked list might work well here: http://en.wikipedia.org/wiki/Linked_list

But that may not be right for this program and/or where you are in the learning process.
Hint:

if x is an integer with the value 0 or 1, then 1 - x is an integer with the value 1 or 0. See how it toggles?
Thanks jsmith, I'll try it tomorrow and let you know how it goes.
Im still having a problem making them alternate. I can get it to go from player 1 to player 2. But I cant get it to switch back to player 1
Looking at the original code there is no possible way for the program to switch players.
Try adding an if-else statement to swap the players.
1
2
3
4
5
6
7
8
if(current == player1)
{
    current = player2;
}
else
{
    current = player1;
}
Thank You SOO much. That was a big help
Topic archived. No new replies allowed.