Game of Nim project. It won't display matches.

Hello everyone,

I am having one issue with my project. We are making a game of Nim code.I'm 99% done with it, i worked hard on it and i feel like i did a good job, however my project is not displaying the matches i want. For example, it display's the inital number of them 23. But once the first player subtracts a number, it doesn't display matches for player 2, just the number of matches remaining. Then as i keep running the program the same thing happens. This is what it's supposed to ouput

Input/Output sample
WELCOME TO NIM 
------- -- --- 
Enter the starting player's name (no spaces)-->John 
Enter the second player's name (no spaces)-->Mary 
There are 23 matches. 
ooooooooooooooooooooooo 
||||||||||||||||||||||| 
Player John please enter the number of matches to remove-->2 
There are 21 matches. 
ooooooooooooooooooooo 
||||||||||||||||||||| 
Player Mary please enter the number of matches to remove-->3 
There are 18 matches. 
oooooooooooooooooo 
|||||||||||||||||| 
Player John please enter the number of matches to remove-->1 



This is my entire code.

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include <iostream>
#include <string>
using namespace std;
int main()
{
	// Holds variables.

	string player1;
	string player2;
	int topMatch = 23;
	int bottomMatch = 23;
	const int total = 23;
	int n, mtotal;
	bool winner = false;

	mtotal = total;

	// Display's Welcome Message to user.

	cout<<"WELCOME TO NIM"<<endl;
	cout<<"------- -- ---"<<endl;

	// Skips a line.

	cout<<endl;

	// Asks player 1 to enter their name.

	cout<<"Enter the starting player's name (no spaces) -->";
	cin>>player1;

	// Skips a line.

	cout<<endl;

	// Asks player 2 to enter their name.

	cout<<"Enter the second player's name (no spaces) -->";
	cin>>player2;

	// Skips a line.

	cout<<endl;
	


// Defines the number of matches.

topMatch=23, bottomMatch=23;















// Beginning of the code.

while (!winner)

{ 
	if(mtotal >= 0)

// Display's message with the total number of matches.

 cout<<"There are "<<mtotal<< " matches." <<endl;


// Display's matches.

while (topMatch > 0)
{
	cout<<"o";
	topMatch--;
}

cout<<endl;

while (bottomMatch > 0)
{
	cout<<"|";
	bottomMatch--;
}

cout<<endl<<endl;

// Ask's player 1 to enter the number of matches he wants to remove.
 cout<<"Player "<<player1<<" please enter the number of matches to remove-->";

 cin>> n;

 cout<<endl;
 

 // Removes only one match if the player enter a number lower than one and higher than 3.

 if ( n<1 || n>3)

 {
	 n=1;
 }

 

// Removes 1 to 3 matches depending on the number entered.

 if ( n >=1 && n <=3)

 {
 mtotal -= n;

 }

 // Equation that removes "matches".

 topMatch=topMatch-n;

 bottomMatch= bottomMatch -n;

 // Removes the number of matches the user inputs.
 while (topMatch > 0)
{
	cout<<"o";
	topMatch--;
}

cout<<endl;

while (bottomMatch > 0)
{
	cout<<"|";

	bottomMatch--;
}
 // Display's Message if player is the winner.

 if (mtotal==0 || mtotal<=0) 

 {winner = true;

cout<<"Game over. Player "<<player2<<" is the winner!"<<endl;
 cin.get ( ); cin.get ( );
 }
 











// Beginning of player 2 coding.

 if(mtotal >= 0)

// Display's the number of matches remaining after player 1 turn.

cout<<"There are "<<mtotal<<" matches"<<endl<<endl;

  // Equation that removes "matches".

 topMatch=topMatch-n;

 bottomMatch= bottomMatch -n;



 // Removes the number of matches the user inputs.
 while (topMatch > 0)
{
	cout<<"o";
	topMatch--;
}

cout<<endl;

while (bottomMatch > 0)
{
	cout<<"|";

	bottomMatch--;
}

// Asks player 2 to remove matches.

cout<<"Player "<<player2<<" please enter the number of matches to remove-->";

cin>>n;

cout<<endl;

 // Removes only one match if the player enter a number lower than one and higher than 3.

 if ( 1>n || n>3)

 {
	 n=1;
 }

 // Equation that removes "matches".

 topMatch=topMatch-n;

 bottomMatch= bottomMatch-n;

 // Removes the number of matches the user inputs.
 while (topMatch > 0)
{
	cout<<"o";
	topMatch--;
}

cout<<endl;

while (bottomMatch > 0)
{
	cout<<"|";

	bottomMatch--;
}
// Removes number of matches entered as long as it's a number between 1 and 3.

if ( n >=1 && n <=3)


	// Display's the number of matches removed from player 2.

 {

mtotal -= n;}





// Display's congratulation message if player 2 has won.

if (mtotal==0 || mtotal<=0) 

 {winner = true;

cout<<"Game over. Player "<<player1<<" is the winner"<<endl;
cin.get ( ); cin.get ( );
}

}
 cin.get ( ); cin.get ( );


 
}	
Topic archived. No new replies allowed.