I have been working on this for the past week and i am almost done but i dont know why my program keeps crashing at the end game
check and also it doesnt realize that there is a piece that interrupts the connect four if it were like XXXOX it still says that X wins and it is due by 12 oclock tonight andi dont know what to due please help!!!!!
I'm using Metroworks Code Warrior and Dev C++ for my writing my programs the code i have so far is below

#include <iostream>
#include <vector>
using namespace std;
int const rows=6;
int const cols=7;
int const connect=4;

void Who_Moves( char cur_val)
{
 
  if (cur_val=='-')
    cout << " "; // val is 0, so draw a space
  else if (cur_val=='O')
    cout << "O"; // val is 1, so draw a 'O'
  else if (cur_val=='*')
    cout << "*"; // val is 2, so draw a '*'
}
 
bool Is_Legal(const vector<vector<char> >Board, int cur_col)
{
  if(Board[0][cur_col] != '-')
        return false;
}

bool Tie_Check(const vector<vector<char> >& Board)
{
    for(int i = 0; i < rows; i++){
      for (int j = 0; j < cols; j++){
        if(Board[i][j] == '-')
        {
        return false; 
        }
            else 
           {
            return true;
           }
        }
    }
}
 
//function that checks to see if the game is over
bool End_Game_Check(const vector<vector<char> >Board, int row, int cur_col, char cur_move){
    //check for horizontal win in the current row (4 cases)
    if(Board[row][0]== cur_move && Board [row][1]== cur_move && Board [row][2]== cur_move && Board[row][3]== cur_move)
       {
        return true; 
        }
       
    if(Board[row][1]== cur_move && Board [row][2]== cur_move && Board [row][3]== cur_move && Board[row][4]== cur_move)
         {
        return true; 
        }
        
    if(Board[row][2]== cur_move && Board [row][3]== cur_move && Board [row][4]== cur_move && Board[row][5]== cur_move)
         {
        return true; 
        }
        
    if(Board[row][3]== cur_move && Board [row][4]== cur_move && Board [row][5]== cur_move && Board[row][6]== cur_move)
         {
        return true; 
        }
        
    //check for vertical win in the current column (3 cases)
    if(Board[5][cur_col] == cur_move && Board[4][cur_col] == cur_move && Board[3][cur_col] && Board[2][cur_col] == cur_move)
        {
        return true; 
        }
        
    if(Board[4][cur_col] == cur_move && Board[3][cur_col] == cur_move && Board[2][cur_col] && Board[1][cur_col] == cur_move)
        {
        return true; 
        }
       
    if(Board[3][cur_col] == cur_move && Board[2][cur_col] == cur_move && Board[1][cur_col] && Board[0][cur_col] == cur_move)
        {
        return true; 
        }
      
    //check for diagonal win that contains the current position (6 cases)
    if(Board[row][cur_col] == Board[row + 1][cur_col- 1] && Board[row + 1][cur_col - 1] == Board[row + 2][cur_col - 2] && Board[row + 2][cur_col - 2] == Board[row + 3][cur_col - 3])
         {
        return true; 
        }
    if(Board[row][cur_col] == Board[row + 1][cur_col - 1] && Board[row + 1][cur_col - 1] == Board[row + 2][cur_col- 2] && Board[row + 2][cur_col- 2] == Board[row - 1][cur_col + 1])
         {
        return true; 
        }
    if(Board[row][cur_col] == Board[row + 1][cur_col - 1] && Board[row + 1][cur_col - 1] == Board[row - 1][cur_col + 1] && Board[row - 1][cur_col + 1] == Board[row - 2][cur_col + 2])
         {
        return true; 
        }
    if(Board[row][cur_col] == Board[row + 1][cur_col + 1] && Board[row][cur_col] == Board[row + 2][cur_col + 2] && Board[row][cur_col] == Board[row + 3][cur_col + 3])
         {
        return true; 
        }
    if(Board[row][cur_col] == Board[row - 1][cur_col - 1] && Board[row][cur_col] == Board[row + 1][cur_col + 1] && Board[row][cur_col] == Board[row + 2][cur_col+ 2])
         {
        return true; 
        }
        
    if(Board[row][cur_col] == Board[row - 2][cur_col - 2] && Board[row][cur_col] == Board[row - 1][cur_col - 1] && Board[row][cur_col] == Board[row + 1][cur_col + 1])
        {
        return true; 
        }
        else
        {
         return false;
        }
}
 
 

 void Print_Board(const vector<vector<char> >&Board)
{
 for (int i=0; i<rows; i++)
 { cout << endl;
  for(int j=0; j<cols; j++)
  {
   cout << Board[i][j];
  }
 cout << endl;
 }
}

 
int main() {
int cur_row; 
int cur_col;
vector<vector<char> >Board;
Board.resize(rows);
for (int i=0; i<rows; i++) { 
Board[i].resize(cols);
for (int j=0; j<cols; j++) {
   Board[i][j] = '-';
    }
}
 
 
 
 Print_Board(Board);

 bool Game_Over=false;
 char cur_move='O';//o goes first

  while (!Game_Over)
 {
  cout<<"Player" << cur_move <<" please enter the column in which you would like your marker placed"<<endl;
  cin >> cur_col;
   while(Is_Legal(Board,cur_col - 1)==false){
   cout << "illegal column please try enter column again"<<endl;
   cin >> cur_col; 
  }
  bool Place_Marker=false;
 int i=5;
    
 do{
   if (Board[i][cur_col-1]=='-')
 {
  Board[i][cur_col-1]=cur_move;
   Place_Marker=true;
 Print_Board(Board);}
 else
{
i--;
}
 }while(Place_Marker=false && i>=0);
Game_Over=End_Game_Check(Board,i , cur_col-1, cur_move);
        if(Game_Over == true)
            cout << endl << cur_move << " has won!" << endl; 
        
        if(Game_Over == false){
            bool Draw = Tie_Check(Board);
            if(Draw == true){
                cout << "There's a DRAW - GAME OVER";
                Game_Over = true;
            }
        }
 
   
   
   
  
  if(cur_move=='O')
  {
   cur_move='*';
  }
 else
 {
  cur_move='O';
 }

 
 }
 

 system("pause");
 return 0;
}

Please help this is the 2nd to last homework of the year for my CS110 class

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

Well for starters it would help if you used code tags instead of inline code tags...

[code][/code]

I have been working on this for the past week and i am almost done but i dont know why my program keeps crashing at the end game
check and also it doesnt realize that there is a piece that interrupts the connect four if it were like XXXOX it still says that X wins and it is due by 12 oclock tonight andi dont know what to due please help!!!!!

Run through the program by hand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.