Like Tree6Likes
  • 3 Post By jimblumberg
  • 1 Post By The Doctor
  • 1 Post By jimblumberg
  • 1 Post By jimblumberg

Need some advices with tic-tac.My code is to long ...

This is a discussion on Need some advices with tic-tac.My code is to long ... within the C++ Programming forums, part of the General Programming Boards category; Code is very long,so i copied it to: Foxefde C++ - Tic tac It would be great if you can ...

  1. #1
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17

    Unhappy Need some advices with tic-tac.My code is to long ...

    Code is very long,so i copied it to:

    Foxefde C++ - Tic tac

    It would be great if you can help to make this code shorter >.>

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,481
    Instead of variables a to i I suggest an array.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2,676
    The code for reference:

    Code:
    #include <iostream>
    using namespace std;
    #include <cstdlib>
    #include <windows.h>
    #include <string>
    #include <sstream>
    #include <cstdio>
    #include <conio.h>
    #define jio "\n\nHello,player X ,in which cell should be X?    "
    #define kio "\n\nHello,player O ,in which cell should be O?    " 
    int main()
    {
    again:
    system("color 9");
    char a=0,b=0,c=0,d=0,f=0,g=0,h=0,e=0,i=0;
    char kva1('1');
    char kva2('2');
    char kva3('3');
    char kva4('4');
    char kva5('5');
    char kva6('6');
    char kva7('7');
    char kva8('8');
    char kva9('9');
    cout<<"Tic takas by Foxefde!\n";
    cout<<"\n\n\n\n";
     cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
     cout<<jio;
     nr1:
     char petras = _getch ();
          if(a==0 & petras==kva1) {a='X';system("cls");}
     else if(b==0 & petras==kva2) {b='X';system("cls");}
     else if(c==0 & petras==kva3) {c='X';system("cls");}
     else if(d==0 & petras==kva4) {d='X';system("cls");}
     else if(e==0 & petras==kva5) {e='X';system("cls");}
     else if(f==0 & petras==kva6) {f='X';system("cls");}
     else if(g==0 & petras==kva7) {g='X';system("cls");}
     else if(h==0 & petras==kva8) {h='X';system("cls");}
     else if(i==0 & petras==kva9) {i='X';system("cls");}
     else goto nr1;
    cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
     cout<<kio;
     nr2:
     char pertas = _getch ();
          if(a==0 & pertas==kva1) {a='O';system("cls");}
     else if(b==0 & pertas==kva2) {b='O';system("cls");}
     else if(c==0 & pertas==kva3) {c='O';system("cls");}
     else if(d==0 & pertas==kva4) {d='O';system("cls");}
     else if(e==0 & pertas==kva5) {e='O';system("cls");}
     else if(f==0 & pertas==kva6) {f='O';system("cls");}
     else if(g==0 & pertas==kva7) {g='O';system("cls");}
     else if(h==0 & pertas==kva8) {h='O';system("cls");}
     else if(i==0 & pertas==kva9) {i='O';system("cls");}
     else goto nr2;
     cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |\n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
      cout<<jio;
      nr3:
     char petrs = _getch ();
          if(a==0 & petrs==kva1) {a='X';system("cls");}
     else if(b==0 & petrs==kva2) {b='X';system("cls");}
     else if(c==0 & petrs==kva3) {c='X';system("cls");}
     else if(d==0 & petrs==kva4) {d='X';system("cls");}
     else if(e==0 & petrs==kva5) {e='X';system("cls");}
     else if(f==0 & petrs==kva6) {f='X';system("cls");}
     else if(g==0 & petrs==kva7) {g='X';system("cls");}
     else if(h==0 & petrs==kva8) {h='X';system("cls");}
     else if(i==0 & petrs==kva9) {i='X';system("cls");}
     else goto nr3;
    cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
     cout<<kio;
     nr4:
     char perta = _getch ();
          if(a==0 & perta==kva1) {a='O';system("cls");}
     else if(b==0 & perta==kva2) {b='O';system("cls");}
     else if(c==0 & perta==kva3) {c='O';system("cls");}
     else if(d==0 & perta==kva4) {d='O';system("cls");}
     else if(e==0 & perta==kva5) {e='O';system("cls");}
     else if(f==0 & perta==kva6) {f='O';system("cls");}
     else if(g==0 & perta==kva7) {g='O';system("cls");}
     else if(h==0 & perta==kva8) {h='O';system("cls");}
     else if(i==0 & perta==kva9) {i='O';system("cls");}
     else goto nr4;
     cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |\n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
      cout<<jio;
      nr5:
     char etra = _getch ();
          if(a==0 & etra==kva1) {a='X';system("cls");}
     else if(b==0 & etra==kva2) {b='X';system("cls");}
     else if(c==0 & etra==kva3) {c='X';system("cls");}
     else if(d==0 & etra==kva4) {d='X';system("cls");}
     else if(e==0 & etra==kva5) {e='X';system("cls");}
     else if(f==0 & etra==kva6) {f='X';system("cls");}
     else if(g==0 & etra==kva7) {g='X';system("cls");}
     else if(h==0 & etra==kva8) {h='X';system("cls");}
     else if(i==0 & etra==kva9) {i='X';system("cls");}
     else goto nr5;
     
    cout<<"           Tic  Tac                               \n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
         if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"      ---"<<a<<"--|---"<<b<<"---|---"<<c<<"---         \n";
     cout<<"            |       |                         \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!Wanna play again?Y/N";kakak: char fox = _getch();if(fox =='y'){system("cls");goto again;} else goto kakak  ;    } 
    else if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!Wanna play again?Y/N";kaka1k:char fox1= _getch();if(fox1=='y'){system("cls");goto again;} else goto kaka1k ;    }
    else if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"            |       |                       \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"      ---"<<g<<"--|---"<<h<<"---|---"<<i<<"---           \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka2k:char fox2= _getch();if(fox2=='y'){system("cls");goto again;} else goto kaka2k ;    }
    else if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"         |  |       |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         |  |       |                    \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"         |  |       |                \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"         |  |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka3k:char fox3= _getch();if(fox3=='y'){system("cls");goto again;} else goto kaka3k ;    }
    else if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |   |   |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |   |   |                    \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |   |   |                \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |   |   |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka4k:char fox4= _getch();if(fox4=='y'){system("cls");goto again;} else goto kaka4k ;    }
    else if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |   |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |   |                \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |               \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |   |            \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |                \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |   |          \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!Wanna play again?Y/N";kaka5k:char fox5= _getch();if(fox5=='y'){system("cls");goto again;} else goto kaka5k ;    }
    else if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"       \\    |       |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"          \\ |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            | \\     |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |     \\ |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       | \\                 \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |     \\         \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!Wanna play again?Y/N";kaka6k:char fox6= _getch();if(fox6=='y'){system("cls");goto again;} else goto kaka6k ;    }
    else if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |     /             \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       | /                  \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |     / |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            | /     |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"          / |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"       /    |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka7k:char fox7= _getch();if(fox7=='y'){system("cls");goto again;} else goto kaka7k ;    }
     else{
     cout<<kio;
     nr6:
     char peas = _getch ();
          if(a==0 & peas==kva1) {a='O';system("cls");}
     else if(b==0 & peas==kva2) {b='O';system("cls");}
     else if(c==0 & peas==kva3) {c='O';system("cls");}
     else if(d==0 & peas==kva4) {d='O';system("cls");}
     else if(e==0 & peas==kva5) {e='O';system("cls");}
     else if(f==0 & peas==kva6) {f='O';system("cls");}
     else if(g==0 & peas==kva7) {g='O';system("cls");}
     else if(h==0 & peas==kva8) {h='O';system("cls");}
     else if(i==0 & peas==kva9) {i='O';system("cls");}
     else goto nr6;
    }
     cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |\n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
         if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n"; cout<<"            |       |                    \n"<<"      ---"<<a<<"--|---"<<b<<"---|---"<<c<<"---         \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!Wanna play again?Y/N";kakakf: char fox = _getch();if(fox =='y'){system("cls");goto again;} else goto kakakf  ;    } 
    else if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n"; 
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!Wanna play again?Y/N";kaka1kf:char fox1= _getch();if(fox1=='y'){system("cls");goto again;} else goto kaka1kf ;    }
    else if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |                   \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"      ---"<<g<<"--|---"<<h<<"---|---"<<i<<"---           \n";
     cout<<"            |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka2kf:char fox2= _getch();if(fox2=='y'){system("cls");goto again;} else goto kaka2kf ;    }
    else if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"         |  |       |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         |  |       |                    \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"         |  |       |                \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"         |  |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka3kf:char fox3= _getch();if(fox3=='y'){system("cls");goto again;} else goto kaka3kf ;    }
    else if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |   |   |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |   |   |                    \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |   |   |                \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |   |   |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka4kf:char fox4= _getch();if(fox4=='y'){system("cls");goto again;} else goto kaka4kf ;    }
    else if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |   |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |   |                \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |               \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |   |            \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |                \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |   |          \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!Wanna play again?Y/N";kaka5kf:char fox5= _getch();if(fox5=='y'){system("cls");goto again;} else goto kaka5kf ;    }
    else if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"       \\    |       |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"          \\ |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            | \\     |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |     \\ |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       | \\                 \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |     \\         \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!Wanna play again?Y/N";kaka6kf:char fox6= _getch();if(fox6=='y'){system("cls");goto again;} else goto kaka6kf ;    }
    else if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |     /             \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       | /                  \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |     / |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            | /     |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"          / |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"       /    |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka7kf:char fox7= _getch();if(fox7=='y'){system("cls");goto again;} else goto kaka7kf ;    }
      else{
      cout<<jio;
      nr7:
     char lukas = _getch ();
          if(a==0 & lukas==kva1) {a='X';system("cls");}
     else if(b==0 & lukas==kva2) {b='X';system("cls");}
     else if(c==0 & lukas==kva3) {c='X';system("cls");}
     else if(d==0 & lukas==kva4) {d='X';system("cls");}
     else if(e==0 & lukas==kva5) {e='X';system("cls");}
     else if(f==0 & lukas==kva6) {f='X';system("cls");}
     else if(g==0 & lukas==kva7) {g='X';system("cls");}
     else if(h==0 & lukas==kva8) {h='X';system("cls");}
     else if(i==0 & lukas==kva9) {i='X';system("cls");}
     else goto nr7;
    }
    cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
         if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"      ---"<<a<<"--|---"<<b<<"---|---"<<c<<"---         \n";
     
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!Wanna play again?Y/N";kakaka: char fox = _getch();if(fox =='y'){system("cls");goto again;} else goto kakaka  ;    } 
    else if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!Wanna play again?Y/N";kaka1ka:char fox1= _getch();if(fox1=='y'){system("cls");goto again;} else goto kaka1ka ;    }
    else if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
    cout<< "            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"      ---"<<g<<"--|---"<<h<<"---|---"<<i<<"---           \n";
     cout<<"            |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka2ka:char fox2= _getch();if(fox2=='y'){system("cls");goto again;} else goto kaka2ka ;    }
    else if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"         |  |       |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         |  |       |                    \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"         |  |       |                \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"         |  |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka3ka:char fox3= _getch();if(fox3=='y'){system("cls");goto again;} else goto kaka3ka ;    }
    else if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |   |   |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |   |   |                    \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |   |   |                \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |   |   |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka4ka:char fox4= _getch();if(fox4=='y'){system("cls");goto again;} else goto kaka4ka ;    }
    else if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |   |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |   |                \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |               \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |   |            \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |                \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |   |          \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!Wanna play again?Y/N";kaka5ka:char fox5= _getch();if(fox5=='y'){system("cls");goto again;} else goto kaka5ka ;    }
    else if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"       \\    |       |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"          \\ |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            | \\     |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |     \\ |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       | \\                 \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |     \\         \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!Wanna play again?Y/N";kaka6ka:char fox6= _getch();if(fox6=='y'){system("cls");goto again;} else goto kaka6ka ;    }
    else if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |     /             \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       | /                  \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |     / |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            | /     |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"          / |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"       /    |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka7ka:char fox7= _getch();if(fox7=='y'){system("cls");goto again;} else goto kaka7ka ;    }
     else {cout<<kio;
     nr8:
     char ukas = _getch ();
          if(a==0 & ukas==kva1) {a='O';system("cls");}
     else if(b==0 & ukas==kva2) {b='O';system("cls");}
     else if(c==0 & ukas==kva3) {c='O';system("cls");}
     else if(d==0 & ukas==kva4) {d='O';system("cls");}
     else if(e==0 & ukas==kva5) {e='O';system("cls");}
     else if(f==0 & ukas==kva6) {f='O';system("cls");}
     else if(g==0 & ukas==kva7) {g='O';system("cls");}
     else if(h==0 & ukas==kva8) {h='O';system("cls");}
     else if(i==0 & ukas==kva9) {i='O';system("cls");}
     else goto nr8;
    }
     cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |\n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
         if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"      ---"<<a<<"--|---"<<b<<"---|---"<<c<<"---         \n";
     
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!Wanna play again?Y/N";kakake :char fox = _getch();if(fox =='y'){system("cls");goto again;} else goto kakake  ;    } 
    else if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!Wanna play again?Y/N";kaka1ke:char fox1= _getch();if(fox1=='y'){system("cls");goto again;} else goto kaka1ke ;    }
    else if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"      ---"<<g<<"--|---"<<h<<"---|---"<<i<<"---           \n";
     cout<<"            |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka2ke:char fox2= _getch();if(fox2=='y'){system("cls");goto again;} else goto kaka2ke ;    }
    else if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"         |  |       |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         |  |       |                    \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"         |  |       |                \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"         |  |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka3ke:char fox3= _getch();if(fox3=='y'){system("cls");goto again;} else goto kaka3ke ;    }
    else if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |   |   |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |   |   |                    \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |   |   |                \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |   |   |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka4ke:char fox4= _getch();if(fox4=='y'){system("cls");goto again;} else goto kaka4ke ;    }
    else if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |   |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |   |                \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |               \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |   |            \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |                \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |   |          \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!Wanna play again?Y/N";kaka5ke:char fox5= _getch();if(fox5=='y'){system("cls");goto again;} else goto kaka5ke ;    }
    else if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"       \\    |       |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"          \\ |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            | \\     |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |     \\ |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       | \\                 \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |     \\         \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!Wanna play again?Y/N";kaka6ke:char fox6= _getch();if(fox6=='y'){system("cls");goto again;} else goto kaka6ke ;    }
    else if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |     /             \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       | /                  \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |     / |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            | /     |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"          / |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"       /    |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka7ke:char fox7= _getch();if(fox7=='y'){system("cls");goto again;} else goto kaka7ke ;    }
    else{  cout<<jio;
      nr9:
     char tras = _getch ();
          if(a==0 & tras==kva1) {a='X';system("cls");}
     else if(b==0 & tras==kva2) {b='X';system("cls");}
     else if(c==0 & tras==kva3) {c='X';system("cls");}
     else if(d==0 & tras==kva4) {d='X';system("cls");}
     else if(e==0 & tras==kva5) {e='X';system("cls");}
     else if(f==0 & tras==kva6) {f='X';system("cls");}
     else if(g==0 & tras==kva7) {g='X';system("cls");}
     else if(h==0 & tras==kva8) {h='X';system("cls");}
     else if(i==0 & tras==kva9) {i='X';system("cls");}
     else goto nr9;
    }
      if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"      ---"<<a<<"--|---"<<b<<"---|---"<<c<<"---         \n";
     cout<<"            |       |                         \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!Wanna play again?Y/N";kakak6: char fox = _getch();if(fox =='y'){system("cls");goto again;} else goto kakak6  ;    } 
    else if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"      ---"<<d<<"--|---"<<e<<"---|---"<<f<<"---            \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!Wanna play again?Y/N";kaka1k5:char fox1= _getch();if(fox1=='y'){system("cls");goto again;} else goto kaka1k5 ;    }
    else if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |                    \n"<<"            |       |                       \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       |                    \n";
     cout<<"      ---"<<g<<"--|---"<<h<<"---|---"<<i<<"---           \n";
     cout<<"            |       |              \n\n\n\n";cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka2k4:char fox2= _getch();if(fox2=='y'){system("cls");goto again;} else goto kaka2k4 ;    }
    else if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"         |  |       |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"         |  |       |                    \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"         |  |       |                \n";
     cout<<"      ---|--|-------|-------          \n";
     cout<<"         |  |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"         |  |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka3k4:char fox3= _getch();if(fox3=='y'){system("cls");goto again;} else goto kaka3k4 ;    }
    else if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |   |   |                    \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |   |   |                    \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |   |   |                \n";
     cout<<"      ------|---|---|-------          \n";
     cout<<"            |   |   |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |   |   |              \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!Wanna play again?Y/N";kaka4k4:char fox4= _getch();if(fox4=='y'){system("cls");goto again;} else goto kaka4k4;    }
    else if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |   |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       |   |                \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |               \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |       |   |            \n";
     cout<<"      ------|-------|---|---          \n";
     cout<<"            |       |   |                \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |   |          \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!Wanna play again?Y/N";kaka5k4:char fox5= _getch();if(fox5=='y'){system("cls");goto again;} else goto kaka5k4 ;    }
    else if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"       \\    |       |                \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"          \\ |       |                    \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            | \\     |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            |     \\ |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |       | \\                 \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"            |       |     \\         \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!Wanna play again?Y/N";kaka6k7:char fox6= _getch();if(fox6=='y'){system("cls");goto again;} else goto kaka6k7;    }
    else if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<"            |       |     /             \n";
     cout<<"         "<<a<<"  |   "<<b<<"   |   "<<c<<"            \n";
     cout<<"            |       | /                  \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"            |     / |                   \n";
     cout<<"         "<<d<<"  |   "<<e<<"   |   "<<f<<"               \n";
     cout<<"            | /     |                \n";
     cout<<"      ------|-------|-------          \n";
     cout<<"          / |       |                    \n";
     cout<<"         "<<g<<"  |   "<<h<<"   |   "<<i<<"              \n";
     cout<<"       /    |       |              \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!Wanna play again?Y/N";kaka78k:char fox7= _getch();if(fox7=='y'){system("cls");goto again;} else goto kaka78k ;    }
     else{
    cout<<"           Tic  Tac                               \n\n\n\n\n\n"; 
     cout<<"           |      |                       |      |                    \n";
     cout<<"        "<<a<<"  |   "<<b<<"  |   "<<c<<"                1  |   2  |   3            \n";
     cout<<"           |      |                       |      |      \n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      | \n";
     cout<<"        "<<d<<"  |   "<<e<<"  |   "<<f<<"                4  |   5  |   6            \n";
     cout<<"           |      |                       |      |\n";
     cout<<"     ------|------|------           ------|------|------\n";
     cout<<"           |      |                       |      |  \n";
     cout<<"        "<<g<<"  |   "<<h<<"  |   "<<i<<"                7  |   8  |   9            \n";
     cout<<"           |      |                       |      |    \n";
     cout<<"\nRestart?Y/N";
     ka:
     char jonas= _getch();
     if(jonas=='y') goto again;
     else goto ka;
    }
    
    
    
    
     
    }
    My advise, stop using the goto statements, and find an indentation style you like and use it consistently. Also you need to try to eliminate redundant code, think about using functions, loops (not goto), and arrays.

    Jim
    stahta01, Salem and Elysia like this.

  4. #4
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Ummm....

    A couple of points:

    1. Divide the program into modules. Use functions (subroutines) to eliminate having to write the same thing over and over again. Consider using classes if you know about them, seeing as you are using C++ (apparently)
    2. "goto"s are generally considered bad practice and there is pretty much no use for them, seeing a c++ (and c for that matter) have a nice range of loops (while loop, do-while loop, for loop, case statements. When I was taught C last year, my teacher mentioned goto, but the extent of it was quite literally "Don't do this, it's not necessary, and quite frankly bad practice."

    Following this will not only shorten your code, it will make it easier to debug, and tell what's going on.
    Elysia likes this.
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  5. #5
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17
    Hi there,thanks everyone for the answers.I tried to edit my code,deleted all the goto functions and now it's 5times shorter than before,any suggestions now?Or it's quite good now?
    By the way ,is there any alternatives for system("cls")?


    Tic tac toe :

    #include <iostream>
    using namespace std;
    #include <cstdlib>
    #include <windows.h>
    #include <string>
    #include <sstream>
    #include <cstdio>
    #include <conio.h>
    #define jio "\n\nHello,player X ,in which cell should be X? "
    #define kio "\n\nHello,player O ,in which cell should be O? "
    char a=0,b=0,c=0,d=0,f=0,g=0,h=0,e=0,i=0;char kva1('1');char kva2('2');char kva3('3');
    char kva4('4');char kva5('5');char kva6('6');char kva7('7');char kva8('8');char kva9('9');
    void nr1()
    {
    if(a=='O' & b=='O' & c=='O' & a!=0 || a=='X' & b=='X' & c=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | \n"<<" ---"<<a<<"--|---"<<b<<"---|---"<<c<<"--- \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | \n\n\n\n";cout<<"\n\nPlayer "<<a<<" is the winner!";cin.ignore(); }
    }
    void nr2()
    {
    if(d=='O' & e=='O' & f=='O' & f!=0 || d=='X' & e=='X' & f=='X' & f!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | \n"<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" ---"<<d<<"--|---"<<e<<"---|---"<<f<<"--- \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | \n\n\n\n";cout<<"\n\nPlayer "<<d<<" is the winner!";cin.ignore(); }
    }
    void nr3()
    {
    if(g=='O' & h=='O' & i=='O' & i!=0 || g=='X' & h=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | \n"<<" | | \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \n";
    cout<<" ---"<<g<<"--|---"<<h<<"---|---"<<i<<"--- \n";
    cout<<" | | \n\n\n\n";cout<<"\n\nPlayer "<<h<<" is the winner!";cin.ignore(); }
    }
    void nr4()
    {
    if(a=='O' & d=='O' & g=='O' & a!=0 || a=='X' & d=='X' & g=='X' & a!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | | \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | | \n";
    cout<<" ---|--|-------|------- \n";
    cout<<" | | | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | | | \n";
    cout<<" ---|--|-------|------- \n";
    cout<<" | | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | | \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!";cin.ignore(); }
    }
    void nr5()
    {
    if(b=='O' & e=='O' & h=='O' & b!=0 || b=='X' & e=='X' & h=='X' & b!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | | \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | | \n";
    cout<<" ------|---|---|------- \n";
    cout<<" | | | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | | | \n";
    cout<<" ------|---|---|------- \n";
    cout<<" | | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | | \n\n\n\n"; cout<<"\n\nPlayer "<<h<<" is the winner!";cin.ignore(); }
    }
    void nr6()
    {
    if(c=='O' & f=='O' & i=='O' & i!=0 || c=='X' & f=='X' & i=='X' & i!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | | \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | | \n";
    cout<<" ------|-------|---|--- \n";
    cout<<" | | | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | | | \n";
    cout<<" ------|-------|---|--- \n";
    cout<<" | | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | | \n\n\n\n"; cout<<"\n\nPlayer "<<f<<" is the winner!";cin.ignore(); }
    }
    void nr7()
    {
    if(a=='O' & e=='O' & i=='O' & a!=0 || a=='X' & e=='X' & i=='X' & a!=0 ) {system("cls");cout<<"Foxefde:]\n\n\n\n\n\n"<<" \\ | | \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" \\ | | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | \\ | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | \\ | \n";
    cout<<" ------|-------|------- \n";
    cout<<" | | \\ \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" | | \\ \n\n\n\n"; cout<<"\n\nPlayer "<<e<<" is the winner!";cin.ignore(); }
    }
    void nr8()
    {
    if(g=='O' & e=='O' & c=='O' & g!=0 || g=='X' & e=='X' & c=='X' & g!=0 ) {system("cls"); cout<<"Foxefde:]\n\n\n\n\n\n"<<" | | / \n";
    cout<<" "<<a<<" | "<<b<<" | "<<c<<" \n";
    cout<<" | | / \n";
    cout<<" ------|-------|------- \n";
    cout<<" | / | \n";
    cout<<" "<<d<<" | "<<e<<" | "<<f<<" \n";
    cout<<" | / | \n";
    cout<<" ------|-------|------- \n";
    cout<<" / | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" \n";
    cout<<" / | | \n\n\n\n"; cout<<"\n\nPlayer "<<g<<" is the winner!";cin.ignore(); }
    }
    void nulis()
    { nr4:
    char perta = _getch ();
    if(a==0 & perta==kva1) {a='O';system("cls");} else if(b==0 & perta==kva2) {b='O';system("cls");}
    else if(c==0 & perta==kva3) {c='O';system("cls");} else if(d==0 & perta==kva4) {d='O';system("cls");}
    else if(e==0 & perta==kva5) {e='O';system("cls");} else if(f==0 & perta==kva6) {f='O';system("cls");}
    else if(g==0 & perta==kva7) {g='O';system("cls");} else if(h==0 & perta==kva8) {h='O';system("cls");}
    else if(i==0 & perta==kva9) {i='O';system("cls");} else nulis();
    }void iksas ()
    {
    nr1:
    char petras = _getch ();
    if(a==0 & petras==kva1) {a='X';system("cls");}else if(b==0 & petras==kva2) {b='X';system("cls");}
    else if(c==0 & petras==kva3) {c='X';system("cls");} else if(d==0 & petras==kva4) {d='X';system("cls");}
    else if(e==0 & petras==kva5) {e='X';system("cls");} else if(f==0 & petras==kva6) {f='X';system("cls");}
    else if(g==0 & petras==kva7) {g='X';system("cls");} else if(h==0 & petras==kva8) {h='X';system("cls");}
    else if(i==0 & petras==kva9) {i='X';system("cls");} else iksas();
    }
    void board ()
    {
    cout<<" Tic Tac \n\n\n\n\n\n" <<" | | | | \n"<<" "<<a<<" | "<<b<<" | "<<c<<" 1 | 2 | 3 \n"<<" | | | | \n"<<" ------|------|------ ------|------|------\n";
    cout<<" | | | | \n"<<" "<<d<<" | "<<e<<" | "<<f<<" 4 | 5 | 6 \n"<<" | | | |\n"<<" ------|------|------ ------|------|------\n"<<" | | | | \n";
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" 7 | 8 | 9 \n"<<" | | | | \n";
    }
    int main()
    {
    system("color 9");
    board (); cout<<jio;iksas();
    cout<<"\nTic tac By F o x e f d e";
    board (); cout<<kio;nulis();
    board (); cout<<jio;iksas();
    board (); cout<<kio;nulis();
    board (); cout<<jio;iksas();

    board ();
    nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8();
    cout<<kio;nulis();board ();
    nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8();
    cout<<jio;iksas();board ();
    nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8();
    cout<<kio;nulis();board ();
    nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8();
    cout<<jio;iksas();board ();
    nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8();co ut<<board;
    system("cls");
    cout<<board<<"\n\nNo one is the winner";
    }





    How to put this code in code format,like jim did?
    Last edited by Foxefde; 03-29-2013 at 10:22 AM.

  6. #6
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    The best way to clear the console is by using a bunch of newlines.

    Code:
    cout << string( 100, '\n' );

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    2,676
    Please post your code inside code tags, don't use an external site.

    Jim
    iMalc likes this.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    2,676
    How to put this code in code format,like jim did?
    You place the code between code tags: [ code]Code here.[/code].

    My next suggestion would be to start adding some whitespace.
    Code:
    cout<<" "<<g<<" | "<<h<<" | "<<i<<" 7 | 8 | 9 \n"<<" | | | | \n";
    cout << " " << g << " | " << h << " | " << i << " 7 | 8 | 9 \n" << " | | | | \n";
    Don't put multiple statements on one line, put them on separate lines.
    Code:
     nr1();nr2();nr3();nr4();nr5();nr6();nr7();nr8(); // BAD
    nr1();
    nr2();
    nr3();
    nr4();
    nr5();
    nr6();
    nr7();
    nr8();
    Next start using meaningful variable and function names. This will really help document your code.

    Also there is a difference in C/C++ between the bitwise operator& and the logical operator&& be sure to use the correct operator in your calculations.

    There is probably more, but The code is too difficult to read for me to continue.


    Jim
    Last edited by jimblumberg; 03-29-2013 at 03:24 PM.
    stahta01 likes this.

  9. #9
    Registered User Foxefde's Avatar
    Join Date
    Mar 2013
    Location
    Lithuania
    Posts
    17
    Ok,no more questions,thanks everyone;]

  10. #10
    Registered User
    Join Date
    Sep 2012
    Posts
    34
    I suggest you write an independent function that will print the gameboard everytime someone plays. That way your code will become 10 times smaller.

    You print the gameboard with the changes in a while cycle. After the play you check for winner (check for strings XXX or OOO? ). If there is a winner you break the cycle and game is over.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-11-2010, 01:53 AM
  2. i need some advices
    By chillout in forum C++ Programming
    Replies: 1
    Last Post: 09-25-2010, 03:28 PM
  3. Advices about an exercise.
    By Tool in forum C Programming
    Replies: 34
    Last Post: 06-08-2010, 09:05 AM
  4. Advices about the approach ?
    By unix7777 in forum C++ Programming
    Replies: 1
    Last Post: 01-18-2009, 11:54 AM
  5. C programming career advices
    By ting in forum A Brief History of Cprogramming.com
    Replies: 51
    Last Post: 03-08-2008, 03:54 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21