this beggining of tic tac toe program, why it no update?

Pages: 12
i will work on check board in a bit, here, i have been working on a way to stop someone from putting an x on a 0 and vice versa, just when they try, they lose there go!

i tried popping a defalt on the end of switch simply to call there go again, but because its a function its only a reference to such data...so i popped an & on the end of 'plyr1' (the code to give player the go but also the code for the switch statement itself) any ideas on how to get the players go back...

have you got to the point where you start to stop understanding your own code??





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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
nclude <iostream>
#include <string>

using namespace std;

int playloop = 0;
char x = 'X';
char o = 'O';
char a,b;
string name;
string name2;
void plyr2 ();
void checkboard();
char brdlog [3] [3];
void getbrdstart ();
void getbrd ();
char input;
void plyr1 ();
int gameloop;
int playloop2;

int main ()

{

getbrdstart ();

cout << "TIC TAC TOE BY DEVONREVENGE\n"<<endl;

cout << "player 1 enter your name..."<<endl;
cin >> name;
cout << "player 2 enter your name..."<<endl;
cin >>name2;

while (gameloop < 10)
{
 while (playloop < 10)
 {
 plyr1 ();
 getbrd ();
 checkboard();
 break;
 }
 while (playloop2 < 10)
 {
 plyr2 ();
 getbrd ();
 checkboard();
 break;
 }
}

return 0;
}

void getbrd ()
{
system("CLS");
cout << brdlog [0] [0] << "|" << brdlog [0] [1] << "|" << brdlog [0] [2]<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [1] [0] <<"|"<<brdlog [1] [1] <<"|"<< brdlog [1] [2] <<endl;
  cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [2] [0] <<"|"<< brdlog [2] [1] <<"|"<< brdlog [2] [2] << endl;

}

void getbrdstart ()
{
cout << "1|2|3"<<endl;
cout << "-+-+-"<<endl;
cout << "4|5|6" <<endl;
  cout << "-+-+-"<<endl;
cout << "7|8|9\n \n" <<endl;
}


void plyr1 ()
{
cout << name << " input number to place your O"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= x )
{brdlog [0] [0] =o;}
break;
case '2':
if (brdlog[0][1]!= x )
{brdlog [0] [1] =o;}
break;
case '3':
if (brdlog[0][2]!= x )
{brdlog [0] [2] =o;}
break;
case '4':
if (brdlog[1][0]!= x )
{brdlog [1] [0] =o;}
break;
case '5':
if (brdlog[1][1]!= x )
{brdlog [1] [1] =o;}
break;
case '6':
if (brdlog[1][2]!= x )
{brdlog [1] [2] =o;}
break;
case '7':
if (brdlog[2][0]!= x )
{brdlog[2] [0] =o;}
break;
case '8':
if (brdlog[2][1]!= x )
{brdlog [2] [1] =o;}
break;
case '9':
if (brdlog[2][2]!= x )
{brdlog [2] [2] =o;}
break;
default:
&plyr1;
}
}

void plyr2()
{
cout << name2 << " input number to place your X"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= o )
{brdlog [0] [0] =x;}
break;
case '2':
if (brdlog[0][1]!= o )
{brdlog [0] [1] =x;}
break;
case '3':
if (brdlog[0][2]!= o )
{brdlog [0] [2] =x;}
break;
case '4':
if (brdlog[1][0]!= o )
{brdlog [1] [0] =x;}
break;
case '5':
if (brdlog[1][1]!= o )
{brdlog [1] [1] =x;}
break;
case '6':
if (brdlog[1][2]!= o )
{brdlog [1] [2] =x;}
break;
case '7':
if (brdlog[2][0]!= o )
{brdlog[2] [0] =x;}
break;
case '8':
if (brdlog[2][1]!= o )
{brdlog [2] [1] =x;}
break;
case '9':
if (brdlog[2][2]!= o )
{brdlog [2] [2] =x;}
break;
default:
&plyr2;
}
}



void checkboard()
{
cout << endl;
}
okayokay i made it into this now, whew im tired and i dont know why it doesnt work...maybe i should just move on to the next challange now anyway...i get it i get it...so sleepy not sure if im giving up or flaking out.

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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#include <iostream>
#include <string>

using namespace std;

int playloop = 0;
char x = 'X';
char o = 'O';
char a,b;
string name;
string name2;
void plyr2 ();
int checkboard();
char brdlog [3] [3];
void getbrdstart ();
void getbrd ();
char input;
void plyr1 ();
int gameloop;
int playloop2;
void twoplaya ();
char c,C,h,H;
char gethorc;
int main ()

{

getbrdstart ();

cout << "TIC TAC TOE BY DEVONREVENGE\n"<<endl;

cout << "player 1 enter your name..."<<endl;
cin >> name;


twoplaya();


if (checkboard()==1)
 {
     cout << "woo " << name2 << " you did it " <<endl;
 }
if (checkboard()==2)
{
    cout << "woo " << name << " you did it " << endl;
}


return 0;
}

void getbrd ()
{
system("CLS");
cout << brdlog [0] [0] << "|" << brdlog [0] [1] << "|" << brdlog [0] [2]<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [1] [0] <<"|"<<brdlog [1] [1] <<"|"<< brdlog [1] [2] <<endl;
  cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [2] [0] <<"|"<< brdlog [2] [1] <<"|"<< brdlog [2] [2] << endl;

}

void getbrdstart ()
{
cout << "1|2|3"<<endl;
cout << "-+-+-"<<endl;
cout << "4|5|6" <<endl;
  cout << "-+-+-"<<endl;
cout << "7|8|9\n \n" <<endl;
}


void plyr1 ()
{
cout << name << " input number to place your O"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= x )
{brdlog [0] [0] =o;}
break;
case '2':
if (brdlog[0][1]!= x )
{brdlog [0] [1] =o;}
break;
case '3':
if (brdlog[0][2]!= x )
{brdlog [0] [2] =o;}
break;
case '4':
if (brdlog[1][0]!= x )
{brdlog [1] [0] =o;}
break;
case '5':
if (brdlog[1][1]!= x )
{brdlog [1] [1] =o;}
break;
case '6':
if (brdlog[1][2]!= x )
{brdlog [1] [2] =o;}
break;
case '7':
if (brdlog[2][0]!= x )
{brdlog[2] [0] =o;}
break;
case '8':
if (brdlog[2][1]!= x )
{brdlog [2] [1] =o;}
break;
case '9':
if (brdlog[2][2]!= x )
{brdlog [2] [2] =o;}
break;
default:
&plyr1;
}
}

void plyr2()
{
cout << name2 << " input number to place your X"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= o )
{brdlog [0] [0] =x;}
break;
case '2':
if (brdlog[0][1]!= o )
{brdlog [0] [1] =x;}
break;
case '3':
if (brdlog[0][2]!= o )
{brdlog [0] [2] =x;}
break;
case '4':
if (brdlog[1][0]!= o )
{brdlog [1] [0] =x;}
break;
case '5':
if (brdlog[1][1]!= o )
{brdlog [1] [1] =x;}
break;
case '6':
if (brdlog[1][2]!= o )
{brdlog [1] [2] =x;}
break;
case '7':
if (brdlog[2][0]!= o )
{brdlog[2] [0] =x;}
break;
case '8':
if (brdlog[2][1]!= o )
{brdlog [2] [1] =x;}
break;
case '9':
if (brdlog[2][2]!= o )
{brdlog [2] [2] =x;}
break;
default:
&plyr2;
}
}



int checkboard()
{

        if(brdlog[0][0] == 'X' && brdlog[0][1] == 'X' && brdlog[0][2] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[1][0] == 'X' && brdlog[1][1] == 'X' && brdlog[1][2] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[2][0] == 'X' && brdlog[2][1] == 'X' && brdlog[2][2] == 'X')
         {

          return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[0][0] == 'X' && brdlog[1][0] == 'X' && brdlog[2][0] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[0][1] == 'X' && brdlog[1][1] == 'X' && brdlog[2][1] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[0][2] == 'X' && brdlog[1][2] == 'X' && brdlog[2][2] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}

        if(brdlog[0][0] == 'X' && brdlog[1][1] == 'X' && brdlog[2][2] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[2][0] == 'X' && brdlog[1][1] == 'X' && brdlog[0][2] == 'X')
          {return 1;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}

        if(brdlog[0][0] == 'O' && brdlog[0][1] == 'O' && brdlog[0][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[1][0] == 'O' && brdlog[1][1] == 'O' && brdlog[1][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[2][0] == 'O' && brdlog[2][1] == 'O' && brdlog[2][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}

        if(brdlog[0][0] == 'O' && brdlog[1][0] == 'O' && brdlog[2][0] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[0][1] == 'O' && brdlog[1][1] == 'O' && brdlog[2][1] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[0][2] == 'O' && brdlog[1][2] == 'O' && brdlog[2][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}

        if(brdlog[0][0] == 'O' &&brdlog[1][1] == 'O' && brdlog[2][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
        if(brdlog[2][0] == 'O' && brdlog[1][1] == 'O' && brdlog[0][2] == 'O')
          {return 0;
          gameloop=gameloop+20;
          playloop=playloop+20;
          playloop2=playloop2+20;}
}

void twoplaya ()
{
 cout << "player 2 enter your name..."<<endl;
cin >>name2;
while (gameloop < 10)
{

 while (playloop < 10)
 {
 plyr1 ();
 getbrd ();
 checkboard();
 playloop++;
 if (playloop == 5)
 {
     cout << "looks like a draw" << endl;
     gameloop=gameloop+20;
     playloop=playloop+20;
     playloop2=playloop2+20;
 }
 break;
 }
 while (playloop2 < 10)
 {
 plyr2 ();
 getbrd ();
 checkboard();
 playloop2++;
 if (playloop == 5)
 {
     cout << "looks like a draw" << endl;
     gameloop=gameloop+20;
     playloop=playloop+20;
     playloop2=playloop2+20;
 }
 break;
 }

}
}





You have 2 long switch statements which are the same - so put in a function. If you find yourself writing the same code over & over then it probably should go in a function.

The checkbrd function should be 3 separate functions - CheckRow, CheckCol & CheckDiag. These functions should make use of nested for loops rather than long winded if statements.
Last edited on
I DID IT...

i actually got it all working, im happy with my switch statments now, i never sussed out how to do the for loop thing for checkboard, i know hat repeating is bad but i realy messed around with the array in the for loop , i got the vague idea its bending your mind around the problem

thanks for you guys help though...next, i pop in a computer player




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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include <iostream>
#include <string>

using namespace std;

int playloop = 0;
char x = 'X';
char o = 'O';
char a,b;
string name;
string name2;
void plyr2 ();
int checkboard();
char brdlog [3] [3];
void getbrdstart ();
void getbrd ();
char input;
void plyr1 ();
int gameloop;
int playloop2;
void twoplaya ();
char c,C,h,H;
char gethorc;
void twopcheck ();

int main ()

{

getbrdstart ();

cout << "TIC TAC TOE BY DEVONREVENGE\n"<<endl;

cout << "player 1 enter your name..."<<endl;
cin >> name;


twoplaya();


return 0;
}

void getbrd ()
{
system("CLS");
cout << brdlog [0] [0] << "|" << brdlog [0] [1] << "|" << brdlog [0] [2]<<endl;
cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [1] [0] <<"|"<<brdlog [1] [1] <<"|"<< brdlog [1] [2] <<endl;
  cout << "-"<< "+" << "-" << "+"<< "-"<<endl;
cout << brdlog [2] [0] <<"|"<< brdlog [2] [1] <<"|"<< brdlog [2] [2] << endl;

}

void getbrdstart ()
{
cout << "1|2|3"<<endl;
cout << "-+-+-"<<endl;
cout << "4|5|6" <<endl;
  cout << "-+-+-"<<endl;
cout << "7|8|9\n \n" <<endl;
}


void plyr1 ()
{
cout << name << " input number to place your O"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= x )
{brdlog [0] [0] =o;}
else if (brdlog[0][0]==x)
{plyr1();}
break;
case '2':
if (brdlog[0][1]!= x )
{brdlog [0] [1] =o;}
else if (brdlog[0][1]==x)
{plyr1();}
break;
case '3':
if (brdlog[0][2]!= x )
{brdlog [0] [2] =o;}
else if (brdlog[0][2]==x)
{plyr1();}
break;
case '4':
if (brdlog[1][0]!= x )
{brdlog [1] [0] =o;}
else if (brdlog[1][0]==x)
{plyr1();}
break;
case '5':
if (brdlog[1][1]!= x )
{brdlog [1] [1] =o;}
else if (brdlog[1][1]==x)
{plyr1();}
break;
case '6':
if (brdlog[1][2]!= x )
{brdlog [1] [2] =o;}
else if (brdlog[1][2]==x)
{plyr1();}
break;
case '7':
if (brdlog[2][0]!= x )
{brdlog[2] [0] =o;}
else if (brdlog[2][0]==x)
{plyr1();}
break;
case '8':
if (brdlog[2][1]!= x )
{brdlog [2] [1] =o;}
else if (brdlog[2][1]==x)
{plyr1();}
break;
case '9':
if (brdlog[2][2]!= x )
{brdlog [2] [2] =o;}
else if (brdlog[2][2]==x)
{plyr1();}
break;
}
}

void plyr2()
{
cout << name2 << " input number to place your X"<<endl;
cin >> input;
switch (input)
{
case '1':
if (brdlog[0][0]!= o )
{brdlog [0] [0] =x;}
else if (brdlog[0][0]==o)
{plyr2();}
break;
case '2':
if (brdlog[0][1]!= o )
{brdlog [0] [1] =x;}
else if (brdlog[0][1]==o)
{plyr2();}
break;
case '3':
if (brdlog[0][2]!= o )
{brdlog [0] [2] =x;}
else if (brdlog[0][2]==o)
{plyr2();}
break;
case '4':
if (brdlog[1][0]!= o )
{brdlog [1] [0] =x;}
else if (brdlog[1][0]==o)
{plyr2();}
break;
case '5':
if (brdlog[1][1]!= o )
{brdlog [1] [1] =x;}
else if (brdlog[1][1]==o)
{plyr2();}
break;
case '6':
if (brdlog[1][2]!= o )
{brdlog [1] [2] =x;}
else if (brdlog[1][2]==o)
{plyr2();}
break;
case '7':
if (brdlog[2][0]!= o )
{brdlog[2] [0] =x;}
else if (brdlog[2][0]==o)
{plyr2();}
break;
case '8':
if (brdlog[2][1]!= o )
{brdlog [2] [1] =x;}
else if (brdlog[2][1]==o)
{plyr2();}
break;
case '9':
if (brdlog[2][2]!= o )
{brdlog [2] [2] =x;}
else if (brdlog[2][2]==o)
{plyr2();}
break;
}
}



int checkboard()
{

        if(brdlog[0][0] == x && brdlog[0][1] == x && brdlog[0][2] == x)
          return 1;
         else if(brdlog[1][0] == x && brdlog[1][1] == x && brdlog[1][2] == x)
          return 1;
         else if(brdlog[2][0] == x && brdlog[2][1] == x && brdlog[2][2] == x)
         return 1;
        else if(brdlog[0][0] == x && brdlog[1][0] ==  x&& brdlog[2][0] == x)
          return 1;
        else if(brdlog[0][1] == x && brdlog[1][1] == x && brdlog[2][1] == x)
          return 1;
        else if(brdlog[0][2] == x && brdlog[1][2] == x && brdlog[2][2] == x)
          return 1;
        else if(brdlog[0][0] == x && brdlog[1][1] == x && brdlog[2][2] == x)
          return 1;
        else if(brdlog[2][0] == x && brdlog[1][1] == x && brdlog[0][2] == x)
          return 1;
        else if(brdlog[0][0] == o && brdlog[0][1] == o && brdlog[0][2] == o)
          return 0;
        else if(brdlog[1][0] ==o  && brdlog[1][1] == o && brdlog[1][2] == o)
          return 0;
        else if(brdlog[2][0] == o && brdlog[2][1] == o && brdlog[2][2] == o)
          return 0;
        else if(brdlog[0][0] == o && brdlog[1][0] == o && brdlog[2][0] == o)
          return 0;
        else if(brdlog[0][1] == o && brdlog[1][1] == o && brdlog[2][1] == o)
          return o;
        else if(brdlog[0][2] == o && brdlog[1][2] == o && brdlog[2][2] == o)
          return 0;
        else if(brdlog[0][0] == o &&brdlog[1][1] == o && brdlog[2][2] == o)
          return 0;
        else if(brdlog[2][0] == o && brdlog[1][1] == o && brdlog[0][2] == o)
          return 0;

}

void twoplaya ()
{
 cout << "player 2 enter your name..."<<endl;
cin >>name2;
while (gameloop < 10)
{
 twopcheck ();
 while (playloop < 10)
 {
 plyr1 ();
 getbrd ();
 checkboard();
 playloop++;
 if (playloop == 5)
 {
     cout << "looks like a draw" << endl;
     gameloop=20;
     playloop=20;
     playloop2=20;
 }
 break;
 }
 twopcheck ();
 while (playloop2 < 10)
 {
 plyr2 ();
 getbrd ();
 checkboard();
 playloop2++;
 if (playloop == 5)
 {
     cout << "looks like a draw" << endl;
     gameloop=20;
     playloop=20;
     playloop2=20;
 }
 break;
 }

}
}



void twopcheck ()
{
if (checkboard()==1)
 {
     cout << "woo " << name2 << " you did it " <<endl;
     gameloop = 20;
     playloop = 20;
 }
if (checkboard()==0)
{
    cout << "woo " << name << " you did it " << endl;
    gameloop = 20;
     playloop2 = 20;
}
}

1
2
3
4
5
6
7
8
unsigned short Row ;
unsigned short Col ;
char Board[3][3];

//initialise the board to z's
for(Row = 0;Row < 3;Row++)
    for(Col = 0 ;Col < 3;Col++)
           Board[Row][Col] = 'z';  //notice the quotes around a char 


You have not quoted your char's throughout your code, and I don't see where you initialised the board.

You can use variations on the above code, instead of the long winded else if statements, to check rows, cols, and diagonals for example. The above code is the same as 9 else-if's.


With this code:
1
2
3
4
5
6
case '1':
if (brdlog[0][0]!= o )
{brdlog [0] [0] =x;}
else if (brdlog[0][0]==o)
{plyr2();}
break;


It is repeated 9 times in the switch (and there are 2 similar switches), so is a good candidate for a function. Using integer division, the input number (1 to 9) less 1, divided by 3 gives the Row, while the remainder gives the Col. So then you could call a function with the Row & Col as arguments, to carry out the same thing as the code above. This way you have the code once instead of 18 times.

My other comment is you need to have proper indenting (4 spaces is the norm)- Your IDE should do this for you.

If you could make these changes, then post the compiler output, if any further problems.

HTH
you and chervil have been a really great help, ive actually learned quite a bit from you two allready, i would post you ice creams but they wud melt...im on it, just need to practice understanding further
Last edited on
It is repeated 9 times in the switch (and there are 2 similar switches), so is a good candidate for a function. Using integer division, the input number (1 to 9) less 1, divided by 3 gives the Row, while the remainder gives the Col. So then you could call a function with the Row & Col as arguments, to carry out the same thing as the code above. This way you have the code once instead of 18 times.


sorry i dont completley understand this, is it using mathmatical magic behind dividing nine s nine is quite clever in some cases...i dont undderstand exactly what it is your saying, ive messed with ways of getting a loop to recognize a sequence that i havnt told it to explicitly recognize

i cant think of a mathmatical pattern that could sort rows and comumns
If your board is numbered like this:

1 2 3
4 5 6
7 8 9

and the user wants to play position 5, then subtract 1, which is 4, divided by 3, is 1 remainder 1, which relates to array position [1][1] - that is Row == 1, and Col ==1, remembering that the array starts at zero.

So you can have a function CheckMove which takes a number ( 1 to 9) as the position to be played, then uses the logic above to see if the move is valid, sets the position in the array if it is, returns an error value if it isn't.

i cant think of a mathmatical pattern that could sort rows and comumns


Why do you want to do that ?
wow thats good thats *snort* mathmagical, how did you know about this kind of maths?

that has been bothering me thank you :)

wanted to sort diagonals,rows and columns to check wins...but no need now
Last edited on
wanted to sort diagonals,rows and columns to check wins...but no need now


I find your use of English a little confusing - I am not sure whether English is your first language, or whether it is just a kind of SMS hybrid.

In the IT world, "sort" means in arrange items in order.

Even if you meant "check" rows, cols & diagonals, I don't see how you can avoid this to check for a win.

Or did you mean that I had given you a solution to achieve this?
yes you given me the solution to achieve this, im learning a whole new way of thinking (i realised that i been asking for too much help when i was tryin to sleep, i realised that your divide and remainder trick works for all grids... all that thinking led to me solving all other problems, i was trying to do it now, next time im stuck ill have a cup of tea)

as for grammer im from rural uk, heres an interesting fact about devon for you, some words like 'er' used for it and themand gurt for huge is actually sanskrit or 20,000 year old language theres otheres too like dimpsy, brimble and coomb that are saxon, so the grammer is a bit different too,

you usa?
I commend you for your knowledge about ancient languages, but I guess my comment was about good communication.

For me, things that can aid this are: complete sentences; good spelling; and punctuation etc.

It is all about expressing your meaning clearly. The point is, if you degrade the language to a point where another English speaking person doesn't understand, then we have a problem.

I find it interesting that I was guessing that English was not your first language, only to discover that you are from the United Kingdom !!

It does remind me of the line from "Lock, Stock & Two Smoking Barrels" :

"I have just flown in from New York, to the north of England, a place where the English language was invented, and I can't understand a word of it !"


I was also guessing that you might be younger (about 20 say), so that's why I suggested the SMS (text message) English hybrid.

I was born in New Zealand, but have been in Australia for a long time.

wow thats good thats *snort* mathmagical, how did you know about this kind of maths?


No one taught me that, I worked it out myself, right there and then. It wasn't that hard.

Problem solving is what programming is all about, trying to come up with elegant ways of solving problems. Often it compares strongly with mathematics.
well i hope to develop both problem solving AND communication skills...you will find americans say they speak american (they may as well say they speak australian) and spell checkers roll with american spelling...its trully horrible what they have don to our language...good to see new australia and especially new zealand are much better
Last edited on
Topic archived. No new replies allowed.
Pages: 12