Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:48 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:40 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:31 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:21 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:14 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:20:07 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:19:59 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !! [link]
      May 24, 2019, 04:19:50 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT ! ! [link]
      May 24, 2019, 04:19:33 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:18:54 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:18:26 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:18:14 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:17:57 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:17:46 PM
    • kingyou: DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!https://www.dissuade614.com/
      May 24, 2019, 04:17:34 PM
    • kingyou:[link]
      May 24, 2019, 04:17:05 PM
    • kingyou:[link]  DID YOU ENJOY [email protected]!!!! WELL THIS IS WAYYYY BETTER ! COME TRY US OUT !!!
      May 24, 2019, 04:16:58 PM
    • PavSwag: BRAND NEW RSPS AUTOSCAPE,ORG FREE MBOX WHEN YOU GET 99 SKILL FOR DONATOR POINTS
      May 22, 2019, 01:52:56 PM
    • Duriall: Join the HYPE TRAIN! New Server - Varrock - Release is tomorrow. Join the discord and forums now for free items on release! [link]
      May 21, 2019, 04:47:56 PM
    • Riskdemon:[link] Varrock OSRS RSPS releasing May 22nd! Discord link provided!
      May 18, 2019, 11:43:14 PM

    Author Topic: Tic-Tac-Toe C++ Passing 2D Arrays  (Read 2116 times)

    0 Members and 1 Guest are viewing this topic.

    Offlinerobonick8

    • Member
    • ***
    • Posts: 128
    • Thanks: +0/-0
      • View Profile
    Tic-Tac-Toe C++ Passing 2D Arrays
    « on: March 09, 2017, 02:38:11 PM »
    Hello Moparscape,

    I am currently making a tic-tace-toe project just for practice
    So far I have the board made which looks like
    Code: [Select]
    void printBoard() {
    for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
    cout << " | " << game[i][j] << " | ";
    }
    cout << endl;
    }
    }
    Outputs:
    1 2 3
    4 5 6
    7 8 9

    So now the next step I was going to do was create the function for the User input to where they want to place there x or o. So far I have
    Game.cpp
    p1 is X and p2 is O
    Code: [Select]
    void userInput(char ** g, char p1, char p2) {
    int a;
    cout << "Enter in number on the board." << endl;

    switch (a) {
    case 1:
    ** g = p1;
    break;
    }

    }
    I know Im missing the rest but I am trying to use a switch statement instead of a bunch of if else statements. My problem is how do I pass a 2D Array and use it in the switch statement to replace the number on the board with the X or O? I am using multiple files Main.cpp Game.cpp and Game.h
    Runescape Gambling

    Offlinerunegay

    • Member
    • ****
    • Posts: 349
    • Thanks: +0/-0
      • View Profile
    Re: Tic-Tac-Toe C++ Passing 2D Arrays
    « Reply #1 on: March 11, 2017, 12:46:05 AM »
    you dont need switch statements or a an if-else block. Just take the users input, and then convert the data to an integer, and then pass the data to a function which modifies the underlying 2d array.
    The CIA hacked my fleshlight and it ripped my dick off
    Runescape Gambling

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal