472,142 Members | 1,183 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

first code, a simple game of tic-tack-toe

2 2Bits
First here is the code that I have built


Expand|Select|Wrap|Line Numbers
  1.  include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. char square[10] = {'0','1','2','3','4','5','6','7','8','9'};
  7.  
  8. int checkwin();
  9. void board();
  10.  
  11. int main () {
  12. {
  13.     int player = 1,i,choice;
  14.     char mark;
  15.     do
  16.     {
  17.         board();
  18.         player=(player%2)?1:2;
  19.         cout << player << ", enter a number : ";
  20.         cin >> choice;
  21.  
  22.         mark=(player == 1) ? 'x' : '0';
  23.  
  24.         if (choice == 1 && square [1] =='1')
  25.             square[1] = mark;
  26.             else if(choice == 2 &&square [2] == '2')
  27.             square[2] = mark;
  28.             else if (choice == 3 &&square[3] == '3')
  29.                 square[3]= mark;
  30.                 else if (choice == 4 &&square [4] == '4')
  31.                     square [4] = mark;
  32.                 else if (choice == 5 &&square [5] == '5')
  33.                     square [5] = mark;
  34.                     else if (choice == 6 &&square [6] == '6')
  35.                         square [6] = mark;
  36.                     else if (choice == 7 &&square [7] == '7')
  37.                         square [7] = mark;
  38.                     else if (choice == 8 &&square [8] == '8')
  39.                     square [8] = mark;
  40.                     else if (choice == 9 &&square [9] == '9')
  41.                         square [9] = mark;
  42.                     else
  43.                     {
  44.  
  45.  
  46.                     cout << "Invaild move ";
  47.  
  48.                     player--;
  49.                     cin.ignore();
  50.                     cin.get();
  51.                     }
  52.                         i=checkwin();
  53.  
  54.                         player++;
  55.                     }while(i==1);
  56.                     board();
  57.                     if(i==1);
  58.                       cout << "==>\aPlayer "<<--player" win ";
  59.                     else;
  60.                         cout <<"==>\aGame draw";
  61.                         cin.ignore();
  62.                     cin.get();
I have an error somewhere in the " cout << "==. \a player" <<--player" win"; line and its saying error expecting ; before string constant and im lost any and all help will be very much apricated
Aug 7 '21 #1
1 4435
dev7060
624 Expert 512MB
Answered here https://bytes.com/topic/general/answ...tring-constant
Aug 22 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Dr_Locke_Z2A | last post: by
3 posts views Thread by paul.sherwood | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.