I am fairly new to C++ and currently following a certification to learn this language. I previously only used languages such as Python.
I found similar posts with the same but none could relate to my code.
I have the following code to create a hex game. I am trying to have a simple function to display the board every time a player makes a moove.
I try to keep the code as simple as possible at first (limit the use of pointers and libraries).
I have this error : hex_game.cpp:9:47: error: expected unqualified-id before 'int' 9 | void display_current_array(array[size][size], int size){ |
Below is my code, hope someone could help :
#include <iostream>
#include <stdlib.h>
using namespace std;
#include <vector>
#include <array>
// a void function to display the array after every moove
void display_current_array(array[size][size], int size){
//s=arr.size();
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
cout<<array[i][j]<<endl;
}
}
}
int main(){
// the HEX game is a game of size cases represented by an array either filled with a color;
// int size =11; //as asked but we can play on a differnt board
int size;
// ask the player to give a board size
cout << "What is the size of your Hex Board ? ";
cin>> size;
// create the array to represent the board
int array[size][size];
// the player will choose colors that we will store as an enum type
enum colors {BLUE, RED};
// initialize the array: all positions are 0
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
array[i][j]=0;
}
}
display_current_array(array, size);
}