while loop with increment and ifelse

im having trouble with my while loop. i need the increment to stop at 9 but its stopping at 10.
so the player clicks and then x and o are suppose to occur. (tic tac toe game). so 5 for x and 4 for 0 but i keep getting 5 and 5 and i have tried to fix it but then i keep getting a total of 8 16 19. help please!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   int counter =0;
         while (counter < 9)
		{
				if (turn % 2 == 0 )// x will get five turns
				{
					Point x = cwin.get_mouse("Player X make your move");
					double x_coord= x.get_x();// get the coordinates of both x and y
					double y_coord= x.get_y();
					Line z(Point (x_coord-2, y_coord+2), Point (x_coord+2, y_coord-2)); 
					Line a(Point (x_coord+2, y_coord+2), Point (x_coord-2, y_coord-2));
					cwin << z << a; //output two lines when clicked
					++counter;
				}
				else (turn % 2 !=0);
				{
					Point c= cwin.get_mouse("Player O make your move");
				     double radius=2.0;//how big the circle will be
					Circle O(c,radius);//points to draw out the circle
					cwin <<O;//ouput the circle
					++counter;
				}
edit:

Reply was incorrect because I can't count, haha
Last edited on
At line 14, else (turn % 2 !=0);
Is a no-op (do nothing) statement.

Either you meant that as a comment, or you left off the if and have an extraneous semicolon. This results in the subsequent code being executed unconditionally.
If turn is even both branches get executed and counter gets double incremented.


Topic archived. No new replies allowed.