Tic-Tac-Toe reaallyyy weird error

So I tried to make Tic-Tac-Toe but stumbled upon this very odd issue. After I say that

char sq1 = char playersymb

sq1 doesn't change!

help please?

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
#include <iostream>

using namespace std;

char sq1 = '1';
char sq2 = '2';
char sq3 = '3';
char sq4 = '4';
char sq5 = '5';
char sq6 = '6';
char sq7 = '7';
char sq8 = '8';
char sq9 = '9';

char P1 = 'X';
char P2 = 'O';

char playersymb;

int vote = 1;
int player = 1;
int b = 1;


int main ()
{
    do
    {

    cout<<sq1<<"|"<<sq2<<"|"<<sq3;
    cout<<"\n-+-+-\n";
    cout<<sq4<<"|"<<sq5<<"|"<<sq6;
    cout<<"\n-+-+-\n";
    cout<<sq7<<"|"<<sq8<<"|"<<sq9;

    if (player == 1)
    {
    playersymb = 'X';
    cout<<"\n\nIt is player "<<player<<" his move.";
    player++;
    }

    else
    {
        playersymb = 'O';
        cout<<"\n\nIt is player "<<player<<" his move.";
        player--;
    }

    cin>> vote;
    if (vote == '1' && sq1 == '1')
        sq1 = playersymb;
    else if (vote == '2' && sq2 == '2')
        sq2 = playersymb;
    else if (vote == '3' && sq3 == '3')
        sq3 = playersymb;
    else if (vote == '4' && sq4 == '4')
        sq4 = playersymb;
    else if (vote == '5' && sq5 == '5')
        sq5 = playersymb;
    else if (vote == '6' && sq6 == '6')
        sq6 = playersymb;
    else if (vote == '7' && sq7 == '7')
        sq7 = playersymb;
    else if (vote == '8' && sq8 == '8')
        sq8 = playersymb;
    else if (vote == '9' && sq9 == '9')
        sq9 = playersymb;

    if (sq1 == playersymb && sq2 == playersymb && sq3 == playersymb) {b = 2;}
    else if (sq1 == playersymb && sq4 == playersymb && sq7 == playersymb) {b = 2;}
    else if (sq9 == playersymb && sq6 == playersymb && sq3 == playersymb) {b = 2;}
    else if (sq9 == playersymb && sq8 == playersymb && sq7 == playersymb) {b = 2;}
    else if (sq5 == playersymb && sq3 == playersymb && sq7 == playersymb) {b = 2;}
    else if (sq5 == playersymb && sq1 == playersymb && sq9 == playersymb) {b = 2;}
    else if (sq5 == playersymb && sq4 == playersymb && sq6 == playersymb) {b = 2;}
    else if (sq5 == playersymb && sq2 == playersymb && sq8 == playersymb) {b = 2;}
    else if (sq1 != 1 && sq2 != 2 && sq3 != 3 && sq4 != 4 && sq5 != 5 && sq6 != 6 && sq7 != 7 && sq8 != 8 && sq9 != 9) {b = 3;}




    }while (b = 1);

    if (b == 2)
    cout<<"player "<<player<<" heeft gewonnen!";
    else
    cout<<"Gelijkspel!";

    return 0;

}


So it basically shows the board again without any change...
First of all I like how you did your player loop. You are testing 'vote' for a char but it is an int. change the data type to char and see what happens.
I haven't read the whole program, but line 83 is probably not what you meant. You're assigning 1 to b instead of testing for equality.
if (vote == '1' && sq1 == '1')
Oops. The decimal ASCII code for 1 is 49. Did you mean:
if (vote == 1 && sq1 == '1')

You'll have to make a few more changes than that one line as well.

EDIT: Check filipe's note as well.

-Albatross
Last edited on
Thanks guys!

I see it all works now! Took out some stupid faults and now it works like a dream!
I'm so excited, I just finished my first true project :D

This site rocks!
Topic archived. No new replies allowed.