Why is this happening?

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
/* INPUT 'X' CHECK */
            if(inputX == 0){
            Block0 = PlayerMarkerX;
            }
            else if(inputX == 1){
                Block1 = PlayerMarkerX;
            }
            else if(inputX == 2){
                Block2 = PlayerMarkerX;
            }
            else if(inputX == 3){
                Block3 = PlayerMarkerX;
            }
            else if(inputX == 4){
                Block4 = PlayerMarkerX;
            }
            else if(inputX == 5){
                Block5 = PlayerMarkerX;
            }
            else if(inputX == 6){
                Block6 = PlayerMarkerX;
            }
            else if(inputX == 7){
                Block7 = PlayerMarkerX;
            }
            else if(inputX == 8){
                Block8 = PlayerMarkerX;
            }
           
            /* INPUT O CHECK */
            if(inputO == 0){
                Block0 = PlayerMarkerO;
            }
            else if(inputO == 1){
                Block1 = PlayerMarkerO;
            }
            else if(inputO == 2){
                Block2 = PlayerMarkerO;
            }
            else if(inputO == 3){
                Block3 = PlayerMarkerO;
            }
            else if(inputO == 4){
                Block4 = PlayerMarkerO;
            }
            else if(inputO == 5){
                Block5 = PlayerMarkerO;
            }
            else if(inputO == 6){
                Block6 = PlayerMarkerO;
            }
            else if(inputO == 7){
                Block7 = PlayerMarkerO;
            }
            else if(inputO == 8){
                Block8 = PlayerMarkerO;
            }



Why is it printing BOTH values at once?

If inputX == 1, it is also printing out inputO. WTF.
I don't see any output statements in the code you posted, so it's impossible to determine why your code is printing unexpected results.
Show the whole source and I'll tell you.

I can't tell why just with your "if" branching conditionals and variables.
It's true that the posted code doesn't give any information about what is or is not printed.

Though if instead of using nine independent variables Block0 to Block8 an array was used like this Block[9], then the original code reduces to just two lines:
1
2
    Block[inputX] = PlayerMarkerX;
    Block[inputO] = PlayerMarkerO;

(to be fair, I've omitted checks for values outside the array bounds).

I've no idea if this gives any insight into the behaviour of the program :)
Last edited on
Topic archived. No new replies allowed.