While statements

This is my program.... Can someone please help me? This is so confusing for me and nothing makes any sense. When I excute the program, it will ask for the 2 names, how chips I want to start with, then it says congrats player 2 name, you win. I have no idea what I am doing wrong.

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 
 #include <iostream>
 #include <iomanip>

 using namespace std;

 int main()
 {
 
 int remainingChips, chipPile, currentChips, Chips = 0;
  
 string player1, player2, currentPlayer;



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


		  
 // ask player 1 for name
 
 cout << "\nPlayer 1 please enter your name: ";
 cin >> player1;
 

 // ask player 2 for name
 
 cout << "Player 2 please enter your name: ";
 cin >> player2;  
  


 //set the current player to player 1
 
 currentPlayer = player1;



 // ask players how many chips they want to start with
 // ask player 1 how many chips they want from the remaining 200 max 100
 // ask player 2 how many chips they want from the remaining chips max half of remaining chips
 
 cout << "\nHow many chips would you like to start with? ";
 cin >> chipPile; 
 

 
  while (Chips > 1)
    {
	  if ( chipPile % 2 == 1 )
         {
		 cout << endl << currentPlayer << " how many of the remaining " << chipPile << " chip(s) would you like to take (" << remainingChips << " max)?";
         cin >> currentChips;
		 }
	  else
	     {
		 cout << endl << currentPlayer << " how many of the remaining " << chipPile << " chip(s) would you like to take (" << remainingChips << " max)?";
         cin >> currentChips;
		 }
	 
	 }
      
	  if( currentChips >= remainingChips / 2 )
        {
        Chips = chipPile - currentChips;
		chipPile ++;
        }
    


 if (chipPile % 2 != 0)
   {
   cout << "Congratulations " << player1 << "! You won!";
   }
 else
   {
   cout << "Congratulations " << player2 << "! You won!";
   }
       	     	 
 return 0;
 }
Your loop does nothing because you are checking for chips which was set 0 instead of (I guess) chipPile

Besides that I think there are other errors in your code
Ok ..... let me try this one. Everything works except at the end. I can go thru and put it amount of chips, when I get to 1 left (1max) it keeps repeating it and doesn't declare a winner. Can anyone help me find where I went wrong ??

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
 int main()
 {


 int takeChips, chipAmt, chips = 0;
    
    
 string player1, player2;


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


		  
 // ask player 1 for name

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

 cout << "\nPlayer 2 please enter your first name: ";
 cin >> player2;
	
 cout << "\nHow many chips would you like to start with? ";
 cin >> chips; 
 	 
 while (chips > 0)
    {
    if (chipAmt % 2 == 0)
	   {
       cout << player1 << " how many of the remaining " << chips << " would you like (" << (chips / 2) << " max)? ";
       }
    else
       {
       cout << player2 << " how many of the remaining " << chips << " would you like (" << (chips / 2) << " max)? ";
       }
	   cin >> takeChips;
       
	   
    if (takeChips <= (chips/2))
       {
       chips = chips - takeChips;
	   chipAmt++;
       }
	else
	   {
	   cout << "\nERROR: invalid number of chips! Try again!";
	   }   
    }

    

    if (chipAmt % 2 != 0)
       {
	   cout << "\nCongratulations " << player1 << "! You won!";
       }
    else
	   {
       cout << "\nCongratulations " << player2 << "! You won!";
       }


return 0;
}
First of all you never initialized chipAmt so it has a random value like 43535.

Second when it reaches the last chip the amount you are able to take is 0 so it never ends.
so should i set it equal to = 0 so it changes?

How can I correct your sencond point?
Topic archived. No new replies allowed.