| | |
problem with tic-tac-toe! help.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 10
Reputation:
Solved Threads: 0
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:
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!
C++ Syntax (Toggle Plain Text)
#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!
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.
All my posts may be redistributed under the GNU Free Documentation License.
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.
You still need to remove char from that line.
All my posts may be redistributed under the GNU Free Documentation License.
![]() |
Similar Threads
- Tic Tac Toe with Classes Problem (C++)
- Tic-Tac-Toe (C++)
- Tic Tac Toe Help (C++)
- C++ help with tic tac toe program (C++)
- Tic Tac Toe Help (Java)
- Tic Tac toe help (C)
Other Threads in the C++ Forum
- Previous Thread: I need to write a C++ Code from the following info. HOW DO I...
- Next Thread: C++ Identifiers and Keywords
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






