Connect Four problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "stdafx.h"


#include <iostream>
#include <string>



int win();
char connectFour[7][6];
char player = 'P';


int main(){
	int condition = win();

	char comp = 'Y';
	char player = 'P';
	char connectFour[7][6];
	
	int horizontal, vertical;
	for (horizontal = 0; horizontal <= 7; horizontal++){
		for (vertical = 0; vertical <= 6; vertical++)
			connectFour[horizontal][vertical] = 'O';
		}
	
	while (condition !=1){

		std::cout << "Enter the horizontal and vertical coordinates for your target place";
		std::cin >> horizontal;
		std::cin >> vertical;
		connectFour[horizontal][vertical] = player;
		std::cout << connectFour;
		std::cout << "Computer's turn...";
		horizontal = rand() % 7;
		vertical = rand() % 7;
		connectFour[horizontal][vertical] = comp;
		std::cout << connectFour;
	}
	if (condition = 1){
		win();
		std::cout << win();
	}
}
int win(){
	if (connectFour[1][1] == connectFour[1][2] && connectFour[1][2] == connectFour[1][3] && connectFour[1][3] == connectFour[1][4] == player){
		std::cout << "Player wins!" << std::endl;
		return 1;
	}
	else{
		return 0;
	}


	

}

(I'm still in the coding process, so it's not finished yet.)
When I run the code, and I enter the horizontal and vertical , it outputs stuff like '004BFA00' , why is that? Please help.
Last edited on
When you print your array connectFour you need to use a series of for loops like this
1
2
3
4
5
6
for (int i = 0; i < 7; i++){
std::cout << std::endl;
for (int x = 0;x < 6;x++){
std::cout << connectFour [i][x];
}
}

This way you are actually printing the values of your array.
std::cout << connectFour; all this does is print the array's hexadecimal address(The address of the memory where the array is stored).
Topic archived. No new replies allowed.