C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 22nd, 2012, 08:30 PM
CWM0120 CWM0120 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 CWM0120 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 58 sec
Reputation Power: 0
Memory & arrays - Connect Four Program

I currently have majority of my coding finished but I am missing two things from it for me to hand it in by midnight tonight. I need to include a section where if the game reaches a tie, it needs to display that. Also after the game finishes, I need to ask the user if he/she would like to play again. Please I need to hand this in tonight it is very important.

Here is my codesorry if it is hard to understand. I am only taking one semester of computer science and this is a huge chunk of my final grade)

#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;

void printArray(int board[][5])
{
cout<<"0 1 2 3 4"<<endl;
cout<<endl;
for(int row=0;row<5;row++)
{
for(int column=0;column<5;column++)
{
cout<<board[row][column]<<" ";

}
cout<<endl;
}



}

int place1(int board[][5], int column, int player)
{
cout<<"Player 1, place your piece."<<endl;
cin>>column;
for(int row=4;row>=0;row--)
{
if(board[row][column]==0)
{board[row][column]=player;
return 0;

}
}
}

int place2(int board[][5], int column, int player)
{
cout<<"Player 2, place your piece."<<endl;
cin>>column;
for(int row=4;row>=0;row--)
{
if(board[row][column]==0)
{board[row][column]=player;
return 0;
}
}
}

int check1(int board[][5])
{


for (int row = 0; row < 5; row++)
{
for (int column = 0; column <5; column++)
{
if((board[0][0]==1 && board[1][0]==1 && board[2][0]==1 && board[3][0]==1) || (board[1][0]==1 && board[2][0]==1 && board[3][0]==1 && board[4][0]==1) ||
(board[0][1]==1 && board[1][1]==1 && board[2][1]==1 && board[3][1]==1) || (board[1][1]==1 && board[2][1]==1 && board[3][1]==1 && board[4][1]==1) ||
(board[0][2]==1 && board[1][2]==1 && board[2][2]==1 && board[3][2]==1) || (board[1][2]==1 && board[2][2]==1 && board[3][2]==1 && board[4][2]==1) ||
(board[0][3]==1 && board[1][3]==1 && board[2][3]==1 && board[3][3]==1) || (board[1][3]==1 && board[2][3]==1 && board[3][3]==1 && board[4][3]==1) ||
(board[0][4]==1 && board[1][4]==1 && board[2][4]==1 && board[3][4]==1) || (board[1][4]==1 && board[2][4]==1 && board[3][4]==1 && board[4][4]==1) ||
(board[0][0]==1 && board[0][1]==1 && board[0][2]==1 && board[0][3]==1) || (board[0][1]==1 && board[0][2]==1 && board[0][3]==1 && board[0][4]==1) ||
(board[1][0]==1 && board[1][1]==1 && board[1][2]==1 && board[1][3]==1) || (board[1][1]==1 && board[1][2]==1 && board[1][3]==1 && board[1][4]==1) ||
(board[2][0]==1 && board[2][1]==1 && board[2][2]==1 && board[2][3]==1) || (board[2][1]==1 && board[2][2]==1 && board[2][3]==1 && board[2][4]==1) ||
(board[3][0]==1 && board[3][1]==1 && board[3][2]==1 && board[3][3]==1) || (board[3][1]==1 && board[3][2]==1 && board[3][3]==1 && board[3][4]==1) ||
(board[4][0]==1 && board[4][1]==1 && board[4][2]==1 && board[4][3]==1) || (board[4][1]==1 && board[4][2]==1 && board[4][3]==1 && board[4][4]==1) ||
(board[0][1]==1 && board[1][2]==1 && board[2][3]==1 && board[3][4]==1) || (board[0][0]==1 && board[1][1]==1 && board[2][2]==1 && board[3][3]==1) ||
(board[1][1]==1 && board[2][2]==1 && board[3][3]==1 && board[4][4]==1) || (board[1][0]==1 && board[2][1]==1 && board[3][2]==1 && board[4][3]==1) ||
(board[0][3]==1 && board[1][2]==1 && board[2][1]==1 && board[3][0]==1) || (board[0][4]==1 && board[1][3]==1 && board[2][2]==1 && board[3][1]==1) ||
(board[1][3]==1 && board[2][2]==1 && board[3][1]==1 && board[4][0]==1) || (board[1][4]==1 && board[2][3]==1 && board[3][2]==1 && board[4][1]==1))
{

cout<<"Player 1 wins!"<<endl;
exit(EXIT_SUCCESS);
}
}
}
}

int check2(int board[][5])
{

for (int row = 0; row < 5; row++)
{
for (int column = 0; column <5; column++)
{
if((board[0][0]==1 && board[1][0]==1 && board[2][0]==1 && board[3][0]==1) || (board[1][0]==1 && board[2][0]==1 && board[3][0]==1 && board[4][0]==1) ||
(board[0][1]==1 && board[1][1]==1 && board[2][1]==1 && board[3][1]==1) || (board[1][1]==1 && board[2][1]==1 && board[3][1]==1 && board[4][1]==1) ||
(board[0][2]==1 && board[1][2]==1 && board[2][2]==1 && board[3][2]==1) || (board[1][2]==1 && board[2][2]==1 && board[3][2]==1 && board[4][2]==1) ||
(board[0][3]==1 && board[1][3]==1 && board[2][3]==1 && board[3][3]==1) || (board[1][3]==1 && board[2][3]==1 && board[3][3]==1 && board[4][3]==1) ||
(board[0][4]==1 && board[1][4]==1 && board[2][4]==1 && board[3][4]==1) || (board[1][4]==1 && board[2][4]==1 && board[3][4]==1 && board[4][4]==1) ||
(board[0][0]==1 && board[0][1]==1 && board[0][2]==1 && board[0][3]==1) || (board[0][1]==1 && board[0][2]==1 && board[0][3]==1 && board[0][4]==1) ||
(board[1][0]==1 && board[1][1]==1 && board[1][2]==1 && board[1][3]==1) || (board[1][1]==1 && board[1][2]==1 && board[1][3]==1 && board[1][4]==1) ||
(board[2][0]==1 && board[2][1]==1 && board[2][2]==1 && board[2][3]==1) || (board[2][1]==1 && board[2][2]==1 && board[2][3]==1 && board[2][4]==1) ||
(board[3][0]==1 && board[3][1]==1 && board[3][2]==1 && board[3][3]==1) || (board[3][1]==1 && board[3][2]==1 && board[3][3]==1 && board[3][4]==1) ||
(board[4][0]==1 && board[4][1]==1 && board[4][2]==1 && board[4][3]==1) || (board[4][1]==1 && board[4][2]==1 && board[4][3]==1 && board[4][4]==1) ||
(board[0][1]==1 && board[1][2]==1 && board[2][3]==1 && board[3][4]==1) || (board[0][0]==1 && board[1][1]==1 && board[2][2]==1 && board[3][3]==1) ||
(board[1][1]==1 && board[2][2]==1 && board[3][3]==1 && board[4][4]==1) || (board[1][0]==1 && board[2][1]==1 && board[3][2]==1 && board[4][3]==1) ||
(board[0][3]==1 && board[1][2]==1 && board[2][1]==1 && board[3][0]==1) || (board[0][4]==1 && board[1][3]==1 && board[2][2]==1 && board[3][1]==1) ||
(board[1][3]==1 && board[2][2]==1 && board[3][1]==1 && board[4][0]==1) || (board[1][4]==1 && board[2][3]==1 && board[3][2]==1 && board[4][1]==1))
{
cout<<"Player 2 wins!"<<endl;
exit(EXIT_SUCCESS);

}


}
}
}

int main()
{
ifstream inputFile("board.txt");
int board [5][5];

for(int row=0;row<5;row++)
{
for(int column=0;column<5;column++)
{inputFile>>board[row][column];

}

}

printArray(board);
cout<<endl;

while(0==0)
{
place1(board,0,1);
printArray(board);
check1(board);
place2(board,0,2);
printArray(board);
check2(board);
}



return 0;
}

Reply With Quote
  #2  
Old November 22nd, 2012, 08:31 PM
CWM0120 CWM0120 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 CWM0120 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 58 sec
Reputation Power: 0
Additional Info

Also I understand I will need to get rid of the exit success but it is what is there for now.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Memory & arrays - Connect Four Program


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap