#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.
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).