Here it is, all the code. Compile it, it works, but the program crashes when CPU attempts to put in 'O', where it already is.
Code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int LOW = 1;
const int HIGH = 9;
char location;
char location1;
char winningsuccess='y';
char state='n';
int cpu_line;
int backup;
int q=0;
char a = 'a', b = 'b', c = 'c', d = 'd', e = 'e', f = 'f', g = 'g', h = 'h', i = 'i';
void showmap();
void cgennum();
void check();
void again();
void user();
void CPUp();
/*laukums
cout<<" a | b | c
cout<<"____|____|____"<<endl;
cout<<" d | e | f "<<endl;
cout<<"____|____|____"<<endl;
cout<<" g | h | i "<<endl;
cout<<" | | "<<endl;
*/
int main()
{cout<<"Sveicinati spele desas!\nSaciet spelet!\n\n";
do{
showmap();
cin>>location;
cin.ignore();
system("cls");
user();
CPUp();
check();
} while (state!=winningsuccess);
showmap();
cout<<"Uzvara!";
cin.get();
return 1;
}
void showmap()
{
cout<<"laukuma karte:\n";
cout<<" "<<a<<" | "<<b<<" | "<<c<<" "<<endl;
cout<<"____|____|____"<<endl;
cout<<" "<<d<<" | "<<e<<" | "<<f<<" "<<endl;
cout<<"____|____|____"<<endl;
cout<<" "<<g<<" | "<<h<<" | "<<i<<" "<<endl;
cout<<" | | \n";
}
void user()
{
switch(location)
{
case 'a': if(a=='a') a = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'b': if(b=='b') b = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'c': if(c=='c') c = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'd': if(d=='d') d = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'e': if(e=='e') e = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'f': if(f=='f') f = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'g': if(g=='g') g = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'h': if(h=='h') h = 'X'; else cout<<"Tur jau ir ielikts"; break;
case 'i': if(i=='i') i = 'X'; else cout<<"Tur jau ir ielikts"; break;
}
}
void cgennum() //changes cpu_line
{
time_t seconds;
time(&seconds);
srand((unsigned int)seconds);
cpu_line = rand() % ( HIGH - LOW + 1) + LOW;
}
void CPUp()
{
cgennum();
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()
{
cpu_line = backup;
while (cpu_line == backup)
{
cgennum();
}
CPUp();
}
void check()
{
if((a==b && b==c) || (d==e && e==f) || (g==h && h==i) || (a==d && d==g) || (b==e && e==h) || (c==f && f==i) || (a==e && e==i) || (g==e && e==c))
state = 'y';
}