chip game

Hey guys, my instructions where to write a chip game, which I have done. Except, I have one issue with my code. It starts off with Player 2, and after it has asked for the number of chips said player would like to have, it keeps repeating that question. The point of the game is that each player is supposed to pick up X amount of chips until all the chips are gone, and the player who picked up the last chip wins.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int main ()
{
int totalchips;
int maxchips;
int chips;
string current;
string player1;
string player2;

cout << "Rules: The game starts with a pile of chips."<<endl;
cout << " Each player may only take at most half of the chips."<<endl;
cout << " The player that gets the last chip wins. Good luck!"<<endl;

cout<< endl;

cout << "Player 1 please enter your first name: ";
cin >> player1;

cout << "Player 2 please enter your first name: ";
cin >> player2;

cout << endl;

cout <<"How many chips would you like to start with? ";
cin >> totalchips;


maxchips=totalchips/2;

if (totalchips%2==1)
{
maxchips+=1;
}

current = player1;

if(current == player1)
{
current = player2;
}
else
{
current = player1;
}

cout << endl << current << " how many of the remaining " << totalchips << " chip(s) would you like ("<<maxchips<< " max): ";
cin >> chips;

while (chips > maxchips || chips <=0)
{
cout <<"invalid number of chips. Try again:"<<endl;
cin >> chips; 
}
for (totalchips = totalchips - chips; totalchips > 0; )
{
maxchips=totalchips/2; 
cout << endl << current << " how many of the remaining " << totalchips << " chip(s) would you like ("<<maxchips<< " max): ";
cin >> chips; 
} 
if (totalchips == 0)
{
cout << " Congratulations "<<current << "! You won!" <<endl; 
}}


Does anyone see a flaw in the code that would make it do this?
Topic archived. No new replies allowed.