Hi i have c++ as a class and decided to do a tic-tac-toe for fun at home. Um I've only been in it for a week. anyways here is the coding so far:

#include <iostream.h>
#include <string.h>
#include <math.h>
#include <iomanip.h>
#include <conio.h> 
#include <stdio.h>



main()
{
char a1='-';
char a2='-';
char a3='-';
char c1='-';
char c2='-';
char c3='-';
char b1='-';
char b2='-';
char b3='-';
char plmove1[3];
char plmove2;
cout << "  1 2 3"<<endl;
cout << "a "<<a1<<" "<<a2<<" "<<a3<<endl;
cout << "b "<<b1<<" "<<b2<<" "<<b3<<endl;
cout << "c "<<c1<<" "<<c2<<" "<<c3<<endl;
cout << endl << endl<< "player 1's turn"<<endl;
cout  << "________" << endl;
cout << "you are: x" <<endl;
cout << "make your move: ";
cin.getline(plmove1, 3);
cout << plmove1;
if (plmove1=="a1")
char a1='x';
system("cls"); 
cout << "  1 2 3"<<endl;
cout << "a "<<a1<<" "<<a2<<" "<<a3<<endl;
cout << "b "<<b1<<" "<<b2<<" "<<b3<<endl;
cout << "c "<<c1<<" "<<c2<<" "<<c3<<endl;
cout << endl << endl<< "player 2's turn"<<endl;
cout  << "________" << endl;
cout << "you are: o" <<endl;
cout << "make your move: ";
cin >> plmove2;  
       

system ("pause");
return 0;
}

well the only problem i want to deal with right now is the fact that variable a1 wont equal 'x'. it stays equal to '-' please help. this is not visual c++, it is c++ using dev-c++. thanks a bunch!

char a1='-';
char a1='x';

The first time you mention 'a1', you have to indicate what type it is. This is what you did in char a1='-';. But afterwards, when assigning a new value to a1, you don't need (or want) to specify the type. So use a1='x'; as to assign to a1.

ive tried that before, doesn't work.
it has to be something wrong with my if statement or the strings.

For starters, you're trying to compare pointers, when you should be doing strcmp. plmove1 and "a1" are both just pointers to arrays of characters, to different arrays of characters, so they won't compare equally. Maybe (definitely) you should use the std::string datatype instead.

You still need to remove char from that line.

This article has been dead for over six months. Start a new discussion instead.