So I made a tic-tac-toe game because thats what everyone does when they start out.
I wanted to share it so I copied it into code playground @ sololearn. Problem is, code playground wants all the inputs before the game starts so you cant see the board until the whole game is played and you submit the inputs before it starts. https://code.sololearn.com/cHzKpH14NrLg/#cpp
You play as if the board is your numberpad (sorry laptop users).
I know i could use switch but im too lazy. copy paste into a proper compiler to test. I have a clear screen before every cout in the home version but im not home at the moment.
#include <iostream>
usingnamespace std;
int main() {
string a="-",b="-",c="-",d="-",e="-",f="-",g="-",h="-",i="-" ;
int x ;
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
if (x==9) {
c="X" ;
}
if (x==8) {
b="X" ;
}
if (x==7) {
a="X" ;
}
if (x==6) {
f="X" ;
}
if (x==5) {
e="X" ;
}
if (x==4) {
d="X" ;
}
if (x==3) {
i="X" ;
}
if (x==2) {
h="X" ;
}
if (x==1) {
g="X" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
if (x==9) {
c="O" ;
}
if (x==8) {
b="O" ;
}
if (x==7) {
a="O" ;
}
if (x==6) {
f="O" ;
}
if (x==5) {
e="O" ;
}
if (x==4) {
d="O" ;
}
if (x==3) {
i="O" ;
}
if (x==2) {
h="O" ;
}
if (x==1) {
g="O" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
if (x==9) {
c="X" ;
}
if (x==8) {
b="X" ;
}
if (x==7) {
a="X" ;
}
if (x==6) {
f="X" ;
}
if (x==5) {
e="X" ;
}
if (x==4) {
d="X" ;
}
if (x==3) {
i="X" ;
}
if (x==2) {
h="X" ;
}
if (x==1) {
g="X" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
if (x==9) {
c="O" ;
}
if (x==8) {
b="O" ;
}
if (x==7) {
a="O" ;
}
if (x==6) {
f="O" ;
}
if (x==5) {
e="O" ;
}
if (x==4) {
d="O" ;
}
if (x==3) {
i="O" ;
}
if (x==2) {
h="O" ;
}
if (x==1) {
g="O" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
if (x==9) {
c="X" ;
}
if (x==8) {
b="X" ;
}
if (x==7) {
a="X" ;
}
if (x==6) {
f="X" ;
}
if (x==5) {
e="X" ;
}
if (x==4) {
d="X" ;
}
if (x==3) {
i="X" ;
}
if (x==2) {
h="X" ;
}
if (x==1) {
g="X" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
if (((a==b)&&(a==c)&&(a!="-"))||
((d==e)&&(d==f)&&(d!="-"))||
((g==h)&&(g==i)&&(g!="-"))||
((a==d)&&(a==g)&&(a!="-"))||
((b==e)&&(b==h)&&(b!="-"))||
((c==f)&&(c==i)&&(c!="-"))||
((a==e)&&(a==i)&&(a!="-"))||
((c==e)&&(c==g)&&(c!="-"))) {
cout << "X wins!" ;
return 0;
}
cin >> x ;
if (x==9) {
c="O" ;
}
if (x==8) {
b="O" ;
}
if (x==7) {
a="O" ;
}
if (x==6) {
f="O" ;
}
if (x==5) {
e="O" ;
}
if (x==4) {
d="O" ;
}
if (x==3) {
i="O" ;
}
if (x==2) {
h="O" ;
}
if (x==1) {
g="O" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
if (((a==b)&&(a==c)&&(a!="-"))||
((d==e)&&(d==f)&&(d!="-"))||
((g==h)&&(g==i)&&(g!="-"))||
((a==d)&&(a==g)&&(a!="-"))||
((b==e)&&(b==h)&&(b!="-"))||
((c==f)&&(c==i)&&(c!="-"))||
((a==e)&&(a==i)&&(a!="-"))||
((c==e)&&(c==g)&&(c!="-"))) {
cout << "O wins!" ;
return 0;
}
cin >> x ;
if (x==9) {
c="X" ;
}
if (x==8) {
b="X" ;
}
if (x==7) {
a="X" ;
}
if (x==6) {
f="X" ;
}
if (x==5) {
e="X" ;
}
if (x==4) {
d="X" ;
}
if (x==3) {
i="X" ;
}
if (x==2) {
h="X" ;
}
if (x==1) {
g="X" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
if (((a==b)&&(a==c)&&(a!="-"))||
((d==e)&&(d==f)&&(d!="-"))||
((g==h)&&(g==i)&&(g!="-"))||
((a==d)&&(a==g)&&(a!="-"))||
((b==e)&&(b==h)&&(b!="-"))||
((c==f)&&(c==i)&&(c!="-"))||
((a==e)&&(a==i)&&(a!="-"))||
((c==e)&&(c==g)&&(c!="-"))) {
cout << "X wins!" ;
return 0;
}
cin >> x ;
if (x==9) {
c="O" ;
}
if (x==8) {
b="O" ;
}
if (x==7) {
a="O" ;
}
if (x==6) {
f="O" ;
}
if (x==5) {
e="O" ;
}
if (x==4) {
d="O" ;
}
if (x==3) {
i="O" ;
}
if (x==2) {
h="O" ;
}
if (x==1) {
g="O" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
if (((a==b)&&(a==c)&&(a!="-"))||
((d==e)&&(d==f)&&(d!="-"))||
((g==h)&&(g==i)&&(g!="-"))||
((a==d)&&(a==g)&&(a!="-"))||
((b==e)&&(b==h)&&(b!="-"))||
((c==f)&&(c==i)&&(c!="-"))||
((a==e)&&(a==i)&&(a!="-"))||
((c==e)&&(c==g)&&(c!="-"))) {
cout << "O wins!" ;
return 0;
}
cin >> x ;
if (x==9) {
c="X" ;
}
if (x==8) {
b="X" ;
}
if (x==7) {
a="X" ;
}
if (x==6) {
f="X" ;
}
if (x==5) {
e="X" ;
}
if (x==4) {
d="X" ;
}
if (x==3) {
i="X" ;
}
if (x==2) {
h="X" ;
}
if (x==1) {
g="X" ;
}
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
if (((a==b)&&(a==c)&&(a!="-"))||
((d==e)&&(d==f)&&(d!="-"))||
((g==h)&&(g==i)&&(g!="-"))||
((a==d)&&(a==g)&&(a!="-"))||
((b==e)&&(b==h)&&(b!="-"))||
((c==f)&&(c==i)&&(c!="-"))||
((a==e)&&(a==i)&&(a!="-"))||
((c==e)&&(c==g)&&(c!="-"))) {
cout << "X wins!" ;
return 0;
}
cout << "Its a draw.";
return 0;
}