1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HELP PLEASE tic tac toe code

Discussion in 'C' started by rmk_for_satan, Oct 12, 2011.

  1. rmk_for_satan

    rmk_for_satan New Member

    Joined:
    Oct 12, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    This is my code so far... please help me


    Code:
    /*
    
    
    KEVON SEEPERSAD
    55500
    mechanical engineering
    
    About the game: this program is designed for two (2) players to play the tic-tac-toe game. The players will be presented
                    with a template grid used for playing the game.
                    Player one (1) will use the (x) character and Player two (2) will use the (o) character
                    
                    The procedure for the game are as follows:
                        1) player 1 will input (x)  first into one of the 9 boxes
                        2) player 2 will input (o) second into one of the 9 boxes which previous player did not use
                        3) repeat steps until
    
    
     rules: a template of the grid is below
            in that grid: number 1-9
            system statement :\ - cls
    
    
    
    while(nowinner)
    {
    display grid
    
    if(count%2 ==0)
    { 
               prompt player 2
               }
               else
               {prompt player 1
               }
               count = count +1
               }
               
    */
    
    
    
    
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
        int boxnumber, count, nowinner;
        char r1c1 = ' ', r1c2 = ' ', r1c3 = ' ', r2c1 = ' ', r2c2 = ' ', r2c3 = ' ', r3c1 = ' ', r3c2 = ' ', r3c3 = ' ';
        
        
        
        cout << "                           WELCOME TO TIC TAC TOE." << endl;
        cout << "This is a (2) Player Game." << endl << endl;
        cout << "Rules Of Game:"<<endl << endl;
        cout << "      1) Player one is: x " << endl;
        cout << "      2) Player two is: o " << endl;
        
    
        
        
        
        
        
        
        
        
        cout <<  "---------------------------------"      << endl;
        cout <<  "|1         |2        |3         |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "--------------------------------- "     << endl;  
        cout <<  "|4         |5        |6         |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "--------------------------------- "     << endl;  
        cout <<  "|7         |8        |9         |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "|          |         |          |"      << endl;
        cout <<  "---------------------------------"      << endl;                                                                                
        
        
        
        
        
        
        
        
    system("pause");    
    system("cls");
    
    
      cout << " Please select a box number to place x in" <<endl ;
        cin >> boxnumber;
        
        if (boxnumber == 1)
        r1c1 = 'x';
        if (boxnumber == 2)
        r1c2 = 'x';
        if (boxnumber == 3)
        r1c3 = 'x';
        if (boxnumber == 4)
        r2c1 = 'x';
        if (boxnumber == 5)
        r2c2 = 'x';
        if (boxnumber == 6)
        r2c3 = 'x';
        if (boxnumber == 7)
        r3c1 = 'x';
        if (boxnumber == 8)
        r3c2 = 'x';
        if (boxnumber == 9)
        r3c3 = 'x';
    
    
    
        cout <<  "------------------------------------"      << endl;
        cout <<  "|1         |2         |3           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r1c1<<"     |     "<<r1c2<<"    |      "<<r1c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------ "     << endl;  
        cout <<  "|4         |5         |6           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r2c1<<"     |     "<<r2c2<<"    |      "<<r2c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------ "     << endl;  
        cout <<  "|7         |8         |9           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r3c1<<"     |     "<<r3c2<<"    |      "<<r3c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------"      << endl << endl;      
        
    system("pause");    
    
    
    
    count = 2;
    
    
    while ((!r1c1=='x' and r1c2 == 'x' and r1c3 == 'x') or
           (!r2c1=='x' and r2c2 == 'x' and r2c3 == 'x') or
           (!r3c1=='x' and r3c2 == 'x' and r3c3 == 'x') or
           (!r1c1=='x' and r2c1 == 'x' and r3c1 == 'x') or
           (!r1c2=='x' and r2c2 == 'x' and r3c2 == 'x') or
           (!r1c3=='x' and r2c3 == 'x' and r3c3 == 'x') or
           (!r1c1=='x' and r2c2 == 'x' and r3c3 == 'x') or
           (!r1c3=='x' and r2c2 == 'x' and r3c1 == 'x') or
           (!r1c1=='o' and r1c2 == 'o' and r1c3 == 'o') or
           (!r2c1=='o' and r2c2 == 'o' and r2c3 == 'o') or
           (!r3c1=='o' and r3c2 == 'o' and r3c3 == 'o') or
           (!r1c1=='o' and r2c1 == 'o' and r3c1 == 'o') or
           (!r1c2=='o' and r2c2 == 'o' and r3c2 == 'o') or
           (!r1c3=='o' and r2c3 == 'o' and r3c3 == 'o') or
           (!r1c1=='o' and r2c2 == 'o' and r3c3 == 'o') or
           (!r1c3=='o' and r2c2 == 'o' and r3c1 == 'o'))
          
    
    {
           
        
        if (count %2 == 0)
        {
          cout << " Please select a box number to place o in" <<endl ;
        cin >> boxnumber;
          
          if (boxnumber == 1)
        r1c1 = 'o';
        if (boxnumber == 2)
        r1c2 = 'o';
        if (boxnumber == 3)
        r1c3 = 'o';
        if (boxnumber == 4)
        r2c1 = 'o';
        if (boxnumber == 5)
        r2c2 = 'o';
        if (boxnumber == 6)
        r2c3 = 'o';
        if (boxnumber == 7)
        r3c1 = 'o';
        if (boxnumber == 8)
        r3c2 = 'o';
        if (boxnumber == 9)
        r3c2 = 'o';
        
        cout <<  "------------------------------------"      << endl;
        cout <<  "|1         |2         |3           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r1c1<<"     |     "<<r1c2<<"    |      "<<r1c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------ "     << endl;  
        cout <<  "|4         |5         |6           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r2c1<<"     |     "<<r2c2<<"    |      "<<r2c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------ "     << endl;  
        cout <<  "|7         |8         |9           |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|    "<<r3c1<<"     |     "<<r3c2<<"    |      "<<r3c3<< "     |"      <<endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "|          |          |            |"      << endl;
        cout <<  "------------------------------------"      << endl << endl;     
        
    }
    
    else {
         cout << "prompt user 1" << endl;
    
    
    }
    count = count + 1;
    
    }
    
    system ("pause");
    return (0);
    }
     

Share This Page