Like Tree1Likes
  • 1 Post By stahta01

Help simplify this Tic-Tac-Toe program

This is a discussion on Help simplify this Tic-Tac-Toe program within the C++ Programming forums, part of the General Programming Boards category; Was wondering if there was anyway to simplify my TTC program. I'm new to programming so yeah, try not to ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    5

    Help simplify this Tic-Tac-Toe program

    Was wondering if there was anyway to simplify my TTC program. I'm new to programming so yeah, try not to go full 1337 on me. Thanks in advance for your responses!

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int where;
    char nothing;
    char X = 'x';
    char O = 'o';
    char e1,e2,e3,e4,e5,e6,e7,e8,e9;
    
    void multi_player()
    {
        system ("cls");
        while  (1)
        {
    
        cout << "|"<<e1<<"|"<<e2<<"|"<<e3<<"|"<<endl;
        cout << "|"<<e4<<"|"<<e5<<"|"<<e6<<"|"<<endl;
        cout << "|"<<e7<<"|"<<e8<<"|"<<e9<<"|"<<endl;
        cout << "\nPlayer One's turn, where?: "<<endl;
        cin >> where;
    
        switch (where)
        {
            case 1:
                e1 = X;
                break;
            case 2:
                e2 = X;
                break;
            case 3:
                e3 = X;
                break;
            case 4:
                e4 = X;
                break;
            case 5:
                e5 = X;
                break;
            case 6:
                e6 = X;
                break;
            case 7:
                e7 = X;
                break;
            case 8:
                e8 = X;
                break;
            case 9:
                e9 = X;
                break;
    
        }
    
    
        system ("cls");
        cout << "|"<<e1<<"|"<<e2<<"|"<<e3<<"|"<<endl;
        cout << "|"<<e4<<"|"<<e5<<"|"<<e6<<"|"<<endl;
        cout << "|"<<e7<<"|"<<e8<<"|"<<e9<<"|"<<endl;
    
        cout << "Player Two's turn, where?: ";
        cin >> where;
            switch (where)
        {
            case 1:
                e1 = O;
                break;
            case 2:
                e2 = O;
                break;
            case 3:
                e3 = O;
                break;
            case 4:
                e4 = O;
                break;
            case 5:
                e5 = O;
                break;
            case 6:
                e6 = O;
                break;
            case 7:
                e7 = O;
                break;
            case 8:
                e8 = O;
                break;
            case 9:
                e9 = O;
                break;
    
        }
    
        system ("cls");
    
    
        }
    
    
    }
    
     int main ()
     {
         cout << "Welcome to TTT DELUXE SUPER EDITION!"<<endl;
         cin >> nothing;
         multi_player ();
    
     }
    Last edited by moombah256; 10-15-2012 at 12:11 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,587
    Code:
    char e1,e2,e3,e4,e5,e6,e7,e8,e9;
    Declaring variables like this is a sign that using an array is likely to make your code smaller.

    Tim S.
    iMalc likes this.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to simplify these conditions ? (engine model c program)
    By Jason Singh in forum C Programming
    Replies: 15
    Last Post: 10-24-2011, 11:41 PM
  2. Can someone help me simplify this?
    By Shackdaddy836 in forum C Programming
    Replies: 1
    Last Post: 10-07-2011, 02:56 PM
  3. Simplify Fraction Help
    By CaliJoe in forum C++ Programming
    Replies: 1
    Last Post: 05-01-2009, 01:17 PM
  4. Can someone simplify this statement from this thead
    By cdalten in forum C Programming
    Replies: 1
    Last Post: 01-30-2006, 07:04 AM
  5. simplify this?
    By markg in forum C Programming
    Replies: 2
    Last Post: 10-25-2005, 08:09 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