944,117 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1820
  • C++ RSS
Aug 15th, 2005
0

problem with tic-tac-toe! help.

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cjm771 is offline Offline
10 posts
since Nov 2004
Aug 15th, 2005
0

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

Quote originally posted by cjm771 ...
C++ Syntax (Toggle Plain Text)
  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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Aug 15th, 2005
0

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

ive tried that before, doesn't work.
it has to be something wrong with my if statement or the strings.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cjm771 is offline Offline
10 posts
since Nov 2004
Aug 16th, 2005
0

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

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I need to write a C++ Code from the following info. HOW DO I...
Next Thread in C++ Forum Timeline: move() function ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC