Tic toch game C++ project without using arrays

i am trying to break the loop when is Game over or When 3 place is match.
example:
X|X|X
-------
0|0|
------
| |
Game over player one is winner.
just like this how can i do this please help me to solve this
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
  #include <iostream>
using namespace std;

class lab02{
private:
    char place1, place2, place3,place4, place5, place6, place7, place8, place9;
public:
    void input(){
        int option;
        char turn;
        place1=place2=place3=place4=place5=place6=place7=place8=place9=' ';
        output();
        for(int i=0;i<9;i++){
            if(i%2==0){
                cout<<"Player 1 ";
                turn = 'X';
            }
            else{
                cout<<"Player 2 ";
                turn = '0';
            }
            cout<<"Enter option: ";
            cin>>option;
            if(option==1&& place1==' ')
                place1=turn;
            else if(option==2&&place2==' ')
                place2=turn;
            else if(option==3&&place3==' ')
                place3=turn;
            else if(option==4&&place4==' ')
                place4=turn;
            else if(option==5&&place5==' ')
                place5=turn;
            else if(option==6&&place6==' ')
                place6=turn;
            else if(option==7&&place7==' ')
                place7=turn;
            else if(option==8&&place8==' ')
                place8=turn;
            else if(option==9&&place9==' ')
                place9=turn;
            else{
                cout<<"Invalid Cell selected!!!"<<endl;
                i--;
            }


   if (place1=='X' && place2=='X'&& place3=='X'|| place4=='X' && place5=='X'&& place6=='X'||place7=='X' && place8=='X'&& place9=='X' || place1=='X' && place4=='X'&& place7=='X'|| place1=='X' && place5=='X'&& place9=='X' || place3=='X' && place6=='X'&& place9=='X'|| place2=='X' && place5=='X'&& place8=='X'|| place3=='X' && place5=='X'&& place7=='X' )

                cout<<"Game over . Winer is player one. "<<endl;


             else if (place1=='0' && place2=='0'&& place3=='0'||place4=='0' && place5=='0'&& place6=='0'|| place7=='0' && place8=='0'&& place9=='0' ||  place1=='0' && place4=='0'&& place7=='0'|| place1=='0' && place5=='0'&& place9=='0'|| place3=='0' && place6=='0'&& place9=='0' || place2=='0' && place5=='0'&& place8=='0'|| place3=='0' && place5=='0'&& place7=='0')
                cout<<"Game Over.player two is winner "<<endl;


               output();




        }




    }
    void output(){
        cout<<endl;
        cout<<" "<<place1<<" | "<<place2<<" | "<<place3<<endl;
cout<<"---|"<<"---|"<<"---"<<endl;
cout<<" "<<place4<<" | "<<place5<<" | "<<place6<<endl;
cout<<"---|"<<"---|"<<"---"<<endl;
cout<<" "<<place7<<" | "<<place8<<" | "<<place9<<endl;

    }
};
int main(){
    lab02 obj;
    obj.input();
    obj.output();

    return 0;

}
Last edited on
Topic archived. No new replies allowed.