problem with tic-tac-toe! help.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 10
Reputation: cjm771 is an unknown quantity at this point 
Solved Threads: 0
cjm771 cjm771 is offline Offline
Newbie Poster

problem with tic-tac-toe! help.

 
0
  #1
Aug 15th, 2005
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:
  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <iomanip.h>
  5. #include <conio.h>
  6. #include <stdio.h>
  7.  
  8.  
  9.  
  10. main()
  11. {
  12. char a1='-';
  13. char a2='-';
  14. char a3='-';
  15. char c1='-';
  16. char c2='-';
  17. char c3='-';
  18. char b1='-';
  19. char b2='-';
  20. char b3='-';
  21. char plmove1[3];
  22. char plmove2;
  23. cout << " 1 2 3"<<endl;
  24. cout << "a "<<a1<<" "<<a2<<" "<<a3<<endl;
  25. cout << "b "<<b1<<" "<<b2<<" "<<b3<<endl;
  26. cout << "c "<<c1<<" "<<c2<<" "<<c3<<endl;
  27. cout << endl << endl<< "player 1's turn"<<endl;
  28. cout << "________" << endl;
  29. cout << "you are: x" <<endl;
  30. cout << "make your move: ";
  31. cin.getline(plmove1, 3);
  32. cout << plmove1;
  33. if (plmove1=="a1")
  34. char a1='x';
  35. system("cls");
  36. cout << " 1 2 3"<<endl;
  37. cout << "a "<<a1<<" "<<a2<<" "<<a3<<endl;
  38. cout << "b "<<b1<<" "<<b2<<" "<<b3<<endl;
  39. cout << "c "<<c1<<" "<<c2<<" "<<c3<<endl;
  40. cout << endl << endl<< "player 2's turn"<<endl;
  41. cout << "________" << endl;
  42. cout << "you are: o" <<endl;
  43. cout << "make your move: ";
  44. cin >> plmove2;
  45.  
  46.  
  47. system ("pause");
  48. return 0;
  49. }

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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: problem with tic-tac-toe! help.

 
0
  #2
Aug 15th, 2005
Originally Posted by cjm771
  1. char a1='-';
  2. 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.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 10
Reputation: cjm771 is an unknown quantity at this point 
Solved Threads: 0
cjm771 cjm771 is offline Offline
Newbie Poster

Re: problem with tic-tac-toe! help.

 
0
  #3
Aug 15th, 2005
ive tried that before, doesn't work.
it has to be something wrong with my if statement or the strings.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: problem with tic-tac-toe! help.

 
0
  #4
Aug 16th, 2005
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.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC