I am creating a connect 4 programme in c++. The programme runs ok but when the programme asks what cell i want to put the X in and i enter a cell referance the X doesn't go in the cell like it should
I was just wondering if anyone would be able to have a look at the code and tell me what wrong
The Code is
Here is a programme of what the programme actually does
I'm thinking the issue is this:
It will repeat these two lines over and over, never doing anything else, since that's how while works -- it repeats what's inside it until its condition becomes false. I suspect you've put your while() loop in the wrong place, if you want it to print the game board every time you take a turn it needs to surround that part too. At the bottom, when you detect a game over condition, you should set game to zero so the loop finishes.
I'm thinking the issue is this:
It will repeat these two lines over and over, never doing anything else, since that's how while works -- it repeats what's inside it until its condition becomes false. I suspect you've put your while() loop in the wrong place, if you want it to print the game board every time you take a turn it needs to surround that part too. At the bottom, when you detect a game over condition, you should set game to zero so the loop finishes.
Yeah thanks for the reply i have fixed it now it was in the wrong place
Just another question i am having trouble adding a second player to the game i havent really got a clue how to do this
You're putting X-es into the array for player one, how about using 1's and 2's instead? That'll make it easier to keep track of the players.
I would declare a variable outside the loop to keep track of whose turn it is, and toggle it back and forth at the top of the loop. Here's a really bare skeleton of the idea:
You're putting X-es into the array for player one, how about using 1's and 2's instead? That'll make it easier to keep track of the players.
I would declare a variable outside the loop to keep track of whose turn it is, and toggle it back and forth at the top of the loop. Here's a really bare skeleton of the idea:
My example replaces your entire while() loop. It's also just a bare skeleton, like I said; there's bits you need to fill in yourself. I'll comment it better to give you more idea what it's doing and what's not finished. I've also fixed some problems I just noticed in my first version.
My example replaces your entire while() loop. It's also just a bare skeleton, like I said; there's bits you need to fill in yourself. I'll comment it better to give you more idea what it's doing and what's not finished. I've also fixed some problems I just noticed in my first version.
Thanks for the reply i don't think i have done it right but i have put the code in there and deleted some like this
I get this error
board.cpp: In function ‘int main()':
board.cpp:66: error: ‘gameover' was not declared in this scope
board.cpp: At global scope:
board.cpp:95: error: expected constructor, destructor, or type conversion before ‘<<' token
board.cpp:97: error: expected declaration before ‘}' token
Is there bits i need to change because i don't really understand it