Hello, i'm having a problem with a tic tac toe game. If CPU tries to put 'O' where already is 'O' or 'X', the program crashes.
Code:
/*Here is the board, each letter is a variable
a | b | c
____|____|____
d | e | f
____|____|____
g | h | i
| |
*/
void CPUp() //function to put in CPU's choice
{
cgennum(); //generates random number for variable cpu_line
switch(cpu_line)
{
case 1: if(a=='a') a = 'O'; else {again();} break;
case 2: if(b=='b') b = 'O'; else {again();} break;
case 3: if(c=='c') c = 'O'; else {again();} break;
case 4: if(d=='d') d = 'O'; else {again();} break;
case 5: if(e=='e') e = 'O'; else {again();} break;
case 6: if(f=='f') f = 'O'; else {again();} break;
case 7: if(g=='g') g = 'O'; else {again();} break;
case 8: if(h=='h') h = 'O'; else {again();} break;
case 9: if(i=='i') i = 'O'; else {again();} break;
}
}
void again() //function to generate another number if the current slot is already full
{
cpu_line = backup;
while (cpu_line == backup)
{
cgennum();
} //when cpu_line changes, try to put 'O' again
CPUp();
}
I hope you understand me, any help would be grateful. If you want, I can post the whole source code here.