I'm a newbie in C++. How can I create a game of tic-tac-toe game using simple codes in C++? Any answers would be much appreciated.. Thanks!:)

hello wintercold,
try using a two dimentional array.

char board[3][3];

then display the board first, then asked where to put the sign.

I'm a newbie in C++. How can I create a game of tic-tac-toe game using simple codes in C++? Any answers would be much appreciated.. Thanks!:)

Use prime numbers instead to make your professor go WTF.

#include <iostream>
#include <string>
        
using namespace std;
                
int main(){
         
int primes[9] = {2,3,5,7,11,13,17,19,23};
        
int x_primes = 1;
int o_primes = 1;
             
string b[9] = {"|   |", "|   |", "|   |", "|   |", "|   |", "|   |", "|   |", "|   |", "|   |"};

char player = 'X';
            
int move;
                 
while (x_primes * o_primes < 223092870){
        
        cout << player << "'s turn.  (press 0-8 where 0 is top left and 8 is bottom right)" << endl;
                
        cin >> move;
                
        if (player == 'X'){
                x_primes *= primes[move];
                b[move] = "| X |";
                player = 'O';
        }

        else {
                o_primes *= primes[move];
                b[move] = "| O |";
                player = 'X';
        }

        cout << b[0] << b[1] << b[2] << endl
             << "---------------\n"
             << b[3] << b[4] << b[5] << endl
             << "---------------\n"
             << b[6] << b[7] << b[8] << endl;

        if (x_primes % 30 == 0 || x_primes % 1001 == 0 || x_primes % 7429 == 0 || x_primes % 238 == 0 || x_primes % 627 == 0 ||
            x_primes % 1495 == 0 || x_primes % 506 == 0 || x_primes % 935 == 0){
                cout << "X wins!" << endl; exit(0);
                }
                 
        if (o_primes % 30 == 0 || o_primes % 1001 == 0 || o_primes % 7429 == 0 || o_primes % 238 == 0 || o_primes % 627 == 0 ||
            o_primes % 1495 == 0 || o_primes % 506 == 0 || o_primes % 935 == 0){
                cout << "Y wins!" << endl; exit(0);
                }
}
cout << "Draw!" << endl;

return 0;
}

-Greywolf bored with SC2

This article has been dead for over six months. Start a new discussion instead.