I made a little tic-tac-toe game. I first made it using a crap ton of if statements after every move to assign a certain variable an X or O. I wanted to make the program a bit shorter so I put the repeating 9 if statements into a function so I can just use the function instead of the 9 if statements. I declared the return type of said function as a character so it returns the one letter variable name so I then equal this to either X or O depending on who's turn it is.
string movemaker () {
if (x==9) {
return c ;
}
if (x==8) {
return b ;
}
if (x==7) {
return a ;
}
if (x==6) {
return f ;
}
if (x==5) {
return e ;
}
if (x==4) {
return d ;
}
if (x==3) {
return i ;
}
if (x==2) {
return h ;
}
if (x==1) {
return g ;
}
}
This is what the code for the first move looks like.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main()
{
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
cin >> x ;
//error message points to this line:
movemaker()="X";
system ("cls");
cout << a << b << c << endl << d << e << f << endl << g << h << i << endl ;
My guess is that the function doesn't know what value x is in your function. Meaning you input x with the cin>>x; but movemaker() doesn't know that. Try making x the parameter of the movemaker function and see what happens. Also, when you say movemaker() equals "X", is that you trying to have the function place an "X" in that spot?