User array input.

I have a program that is supposed to simulate a tic tac toe game. I do not know how to have a user input the location in the two dimensional array, and then assign a character to that location. So far I have this.

1
2
3
4
   cout<<"Please enter the row number followed by the column number: "<<endl;
                
                cin>>ttt[][];
                
I have the program written now, but I cannot run it. Any help figuring out my error would be appreciated.

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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    
    
    
char ttt[3][3];
string playerone, playertwo;
cout<<"Welcome to tic tac toe. There will be two players."<<endl;
cout<<"Player one, please enter your name. No spaces please: ";
cin>>playerone;
cout<<"Player two, please enter your name: "; 
cin>>playertwo;
cout<<"Thankyou both. The gameboard will soon be displayed. You will take turns "<<endl;
cout<<"deciding where you want to make your mark on the board. Player one will  "<<endl;
cout<<"use an X while player two uses an O. All entries will be in capital.  "<<endl;
cout<<"A winner will be decided when a player gets three letters in a row. "<<endl;
cout<<"If the game board fills up, CAT will be declared the winner." <<endl;



int row, column, turn;

 for(turn=1; turn<11; turn++)
      {       
            char userRow, userColumn;  
              
              
              if (turn%2==1)
                {cout<<playertwo <<" it is your turn\n";}
                else {cout<<playerone <<" it is your turn\n";}
                
             cout<<"Here is the board for this turn: " <<endl;
             
                for (row=0; row<3; row++)
                    {for (column=0; column<3; column++)
                         {cout<<setw(3) <<ttt[row][column];}
                         }
                    cout<<"Please enter the row number followed by the column number: "<<endl;
                
                cin>>userRow, userColumn;
                if (turn%2==1) 
                   {
                               
                               ttt[userRow][userColumn]='O';}
                   
                   else
                       {ttt[userRow][userColumn]='Y';}
                
                
                
                
                if (turn>5)
                { if (ttt[1][1]=='X' && ttt[1][2]=='X' && ttt[1][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][1]=='X' && ttt[3][1]=='X')
                                     {cout<<"Player one is the winner!!!";}               
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}   
                            system ("pause");
                              
                              return 0;
                  if (ttt[2][1]=='X' && ttt[2][2]=='X' && ttt[2][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='X' && ttt[3][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}     
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][2]=='X' && ttt[2][2]=='X' && ttt[3][2]=='X')
                                     {cout<<"Player one is the winner!!!";}
                     system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='X' && ttt[3][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
 system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][2]=='X' && ttt[3][1]=='X')
                                     {cout<<"Player one is the winner!!!";}

 system ("pause");
                              
                              return 0;

                  if (ttt[1][1]=='O' && ttt[1][2]=='O' && ttt[1][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][1]=='O' && ttt[3][1]=='O')
                                     {cout<<"Player two is the winner!!!";}               
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}   
                            system ("pause");
                              
                              return 0;
                  if (ttt[2][1]=='O' && ttt[2][2]=='O' && ttt[2][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='O' && ttt[3][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}     
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][2]=='O' && ttt[2][2]=='O' && ttt[3][2]=='O')
                                     {cout<<"Player two is the winner!!!";}
                     system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='O' && ttt[3][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
 system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][2]=='O' && ttt[3][1]=='O')
                                     {cout<<"Player two is the winner!!!";}
            
             system ("pause");
                              
                              return 0;
            
            }



               if (turn>9)
                  {cout<<"CAT is the winner!?! :X  lol";
                              system ("pause");
                              
                              return 0;
}
}
}



I fixed a few things in my code, but it still freezes. Also, it won't correctly display the array.









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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
    
    
    
char ttt[3][3]={{'a', 'a', 'a'},
                {'a', 'a', 'a'},
                {'a', 'a', 'a'}};  
string playerone, playertwo;
cout<<"Welcome to tic tac toe. There will be two players."<<endl;
cout<<"Player one, please enter your name. No spaces please: ";
cin>>playerone;
cout<<"Player two, please enter your name: "; 
cin>>playertwo;
cout<<"Thankyou both. The gameboard will soon be displayed. You will take turns "<<endl;
cout<<"deciding where you want to make your mark on the board. Player one will  "<<endl;
cout<<"use an X while player two uses an O. All entries will be in capital.  "<<endl;
cout<<"A winner will be decided when a player gets three letters in a row. "<<endl;
cout<<"If the game board fills up, CAT will be declared the winner." <<endl <<endl;



int row, column, turn;

 for(turn=1; turn<11; turn++)
      {       
            char userRow, userColumn;  
              
              
              if (turn%2==1)
                {cout<<playertwo <<" it is your turn\n";}
                else {cout<<playerone <<" it is your turn\n";}
                
             cout<<"Here is the board for this turn: " <<endl;
             
                for (row=0; row<3; row++)
                    {for (column=0; column<3; column++)
                         {cout<<setw(3) <<ttt[row][column] <<" ";}
                         }
                    cout<<"Please enter the row number followed by the column number: "<<endl;
                
                cin>>userRow, userColumn;
                if (turn%2==1) 
                   {
                               
                               ttt[userRow][userColumn]='O';}
                   
                   else
                       {ttt[userRow][userColumn]='Y';}
                
                
                
                
                if (turn>5)
                { if (ttt[1][1]=='X' && ttt[1][2]=='X' && ttt[1][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][1]=='X' && ttt[3][1]=='X')
                                     {cout<<"Player one is the winner!!!";}               
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}   
                            system ("pause");
                              
                              return 0;
                  if (ttt[2][1]=='X' && ttt[2][2]=='X' && ttt[2][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='X' && ttt[3][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}     
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][2]=='X' && ttt[2][2]=='X' && ttt[3][2]=='X')
                                     {cout<<"Player one is the winner!!!";}
                     system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='X' && ttt[3][2]=='X' && ttt[3][3]=='X')
                                     {cout<<"Player one is the winner!!!";}
 system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='X' && ttt[2][2]=='X' && ttt[3][1]=='X')
                                     {cout<<"Player one is the winner!!!";}

 system ("pause");
                              
                              return 0;

                  if (ttt[1][1]=='O' && ttt[1][2]=='O' && ttt[1][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][1]=='O' && ttt[3][1]=='O')
                                     {cout<<"Player two is the winner!!!";}               
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}   
                            system ("pause");
                              
                              return 0;
                  if (ttt[2][1]=='O' && ttt[2][2]=='O' && ttt[2][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
                   system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='O' && ttt[3][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}     
                   system ("pause");
                              
                              return 0;
                  if (ttt[1][2]=='O' && ttt[2][2]=='O' && ttt[3][2]=='O')
                                     {cout<<"Player two is the winner!!!";}
                     system ("pause");
                              
                              return 0;
                  if (ttt[3][1]=='O' && ttt[3][2]=='O' && ttt[3][3]=='O')
                                     {cout<<"Player two is the winner!!!";}
 system ("pause");
                              
                              return 0;
                  if (ttt[1][1]=='O' && ttt[2][2]=='O' && ttt[3][1]=='O')
                                     {cout<<"Player two is the winner!!!";}
            
             system ("pause");
                              
                              return 0;
            
            }



               if (turn>9)
                  {cout<<"CAT is the winner!?! :X  lol";
                              system ("pause");
                              
                              return 0;
}
}
}



Topic archived. No new replies allowed.