converting int stored in array to char?

This is a discussion on converting int stored in array to char? within the C++ Programming forums, part of the General Programming Boards category; Doing another exercise on array, making another tic tac toe game, but now with varied board size. So I can't ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77

    converting int stored in array to char?

    Doing another exercise on array, making another tic tac toe game, but now with varied board size. So I can't use board with char type.
    Unless there's another way to show that the square is marked with O and X, I want to know how to convert int values stored in array into a char.

    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    
    void show_board(int board[][6],int board_size);
    int game_start(int board[][6], string player[]);
    int select_board(int board[][6]);
    
    
    void player_names(string player[])
    {   string player1,player2;
        std::cout << "Player 1's name: ";
        std::getline(cin, player1);
        std::cout<<endl;
        std::cout << "Player 2's name: ";
        std::getline(cin, player2);
        std::cout <<endl;
    
    
        player[0]= player1;
        player[1]= player2;
    
    
    }
    
    
    int game_start(int board[][6], string player[],int board_size)
    {
        bool gameover = false;
        int turn =0; //0-'X', 1-'O'
        int mark;
    
    
        do{
    
    
            show_board(board,board_size);
    
    
            std::cout << player[0]<< "'s turn.\n";
            std::cin>>mark;
    
    
            for (int row=0;row<board_size;row++)
            {
                for(int column=0;column<board_size;column++)
                {
                    if(board[row][column] == mark && turn == 0 ){
    
    
                       
    
    
                    }
                    else if(board[row][column] == mark && turn == 1){
    
    
                         
                    }
                }
            }
    
    
    
    
    
    
    
    
    
    
        }
        while(!gameover);
    }
    
    
    
    
    void show_board(int board[][6],int board_size)
    {
    
    
        for (int row=0;row<board_size;row++)
        {
             for(int column=0;column<board_size;column++)
            {
                 if(board_size == 5){
                    if(board[row][column] > 24){
                    board[row][column] = board[row][column] - 4;}
                    else if (board[row][column] > 18){
                    board[row][column] = board[row][column] - 3;}
                    else if (board[row][column] > 12){
                    board[row][column] = board[row][column] - 2;}
                    else if (board[row][column] > 6){
                    board[row][column] = board[row][column] - 1;}
                 }
                 else if(board_size == 4){
                     if(board[row][column] > 18){
                    board[row][column] = board[row][column] - 6;}
                    else if (board[row][column] > 12){
                    board[row][column] = board[row][column] - 4;}
                    else if (board[row][column] > 6){
                    board[row][column] = board[row][column] - 2;}
    
    
                 }
    
    
                 if (board[row][column] < 10){
                 std::cout << " ";}
    
    
    
    
    
    
                std::cout << board[row][column] << " ";
            }
            std::cout << endl;
        }
    }
    
    
    int select_board(int board[][6])
    {
        std::cout << "Select the size of board: \n";
        std::cout << " 4x4 - press 4.\n";
        std::cout << " 5x5 - press 5.\n";
        std::cout << " 6x6 - press 6.\n";
        int board_size;
        std::cin >> board_size;
    
    
        return board_size;
    }
    int main()
    {
        int board[6][6] = { {1,2,3,4,5,6},
                            {7,8,9,10,11,12} ,
                            {13,14,15,16,17,18},
                            {19,20,21,22,23,24},
                            {25,26,27,28,29,30},
                            {31,32,33,34,35,36}};
        string player[2];
        player_names(player);
        int board_size = select_board(board);
    
    
        game_start(board,player,board_size);
    }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    ahh something i overlook the board too =.=

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting string to char array
    By frankchester in forum C Programming
    Replies: 13
    Last Post: 12-01-2010, 12:33 AM
  2. converting char array to string.
    By jas_atwal in forum C Programming
    Replies: 9
    Last Post: 12-31-2007, 05:25 AM
  3. Converting String to Char Array
    By Tanner.B in forum C++ Programming
    Replies: 2
    Last Post: 04-06-2007, 11:17 PM
  4. Hex digits stored in char array.
    By Kevinmun in forum C Programming
    Replies: 8
    Last Post: 11-18-2005, 03:05 PM
  5. Converting const char to char array
    By HomerJ in forum C++ Programming
    Replies: 4
    Last Post: 04-30-2002, 03:21 PM

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