hello,
i have just started trying to learn c++ and have been told to create a game of connect four player vs comp. i have managed very little and am stuck on trying to get the computer to recognise that when the cell is occupied rather than not put the coin in ('@') at all it will replace the ('_') above the '@' instead,
any ideas would be greatful thank you
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <limits>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
int main()
{
//char a[] = {'|','_','|','_','|','_','|','_','|','_','|','_','|','_','|'};
char a[] = {'|','_','|','_','|','_','|','_','|','_','|','_','|','_','|'};
char b[] = {'|','1','|','2','|','3','|','4','|','5','|','6','|','7','|'};
char board[6][7];
int i, j, k =0;
int row;
int column;
int game =1;
int r = rand() ;
for (i=0; i<6; i++)
for (j=0; j<7; j++)
board[i][j] = ' ';
srand ( time(NULL) );
cout<<"";
for( j = 0; j<15; j++)
cout <<b[j];
cout <<endl;
for ( i=0; i<6; i++)
{ //cout <<i+1;
for( j = 0; j<15; j++)
cout <<a[j];
cout <<endl;
}
while(game ==1)
{
cout << "your turn please enter which cell you would like" << endl;
cin >> column;
if(board[5][column-1] ==' '){
board[5][column-1] = '@';
}else if(board[5][column-1] == '@')
cout << "Cell Not Empty, Choose another cell" <<endl;
cout<<"";
for( j = 0; j<15; j++)
cout <<b[j];
cout <<endl;
for(i =0; i<6; i++){
cout<<'|';
for(j = 0; j<7; j++){
if(i < 5 && board[i][j] == '@' && board[i+1][j] == ' ') {board[i][j] =' '; board[i+1][j] ='@';}
if(board[i][j] =='@' ) cout<<board[i][j]<<'|';
else cout <<'_'<<'|';
}
cout <<endl;
}
k++;
if( k ==10){
game =0; // game over
}
}
//cout << "thank you, computer's turn" << endl;
// int r = rand() % 7;
//cout << (rand() % 6) << endl;
//cout << (rand() % 7) <<endl;
cout << "Game over !" <<endl;
return 0;
}