#pls i really need help with hw

15 messages · Page 1 of 1 (latest)

neat ravine
#

Im basically trying to code a grid based game, which im doing tick tack toe. its also based of a lesson of arrays. im so lost and would really appreciate help :( this is what i have so far

#include <iostream>
using namespace std;

void Board(char gridGame [3][3]){
    for (int i = 0; i <= 2; i++){
        for (int j = 0; j <= 2; j++){
            cout << gridGame[i][j] << "|";
        }
        cout << endl;
    }
}


int main(){

    char gridGame [3][3] = {};
    int column = 0;
    int row = 0;
    bool player1turn = true;
    bool running = true;
    while (running) {
        if (player1turn){
            cout << "Player 1, which COLUMN would you like to go? ";
            cin >> column;
            column--;
            cout << "player 1, which ROW would you like to go? ";
            cin >> row;
            row--;
            if (gridGame[column][row] == '\0'){
                gridGame[column][row] = 'X';
            }
        }
        Board(gridGame);
        if (!player1turn){
            cout << "Player 2, which COLUMN would you like to go? ";
            cin >> column;
            column--;
            cout << "player 2, which ROW would you like to go? ";
            cin >> row;
            row--;
            if (gridGame[column][row] == '\0'){
                gridGame[column][row] = 'O';
            }
        }
        Board(gridGame);
    }
}
tidal ploverBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

patent drift
patent drift
#

change the language to cpp...

neat ravine
#

i was with a tutor in person but the tutor center closed and i just need help finishing it. I know i need to add in stuff for check win, ending the game, and i cant remember what else the tutor said. im sorry but im not very good at these kinds of stuff

patent drift
#

The code looks fine, what help do you exactly?

neat ravine
#

just adding check win, ending the game, and i think who won or if it tied

patent drift
#

Well for the grid I prefer having like number selection instead of just selecting coordinate
Sample

1 O 3
4 X O
7 X 9

and the users will just enter the number where to attack

patent drift
#

You can do

bool is_win(char player, char** board);
#

like you check if 0,0 0,1 0,2 are all same as player

#

this way you can use this checker for both player

neat ravine
#

mhh okay okay

#

so that bool would go under the void that i have rn