Hello, I've been having a problem with my arrays. The error that I am receiving says "[my array] undeclared (first use this function)" and "invalid types 'bool[int]' for array subscripts". My code has the following setup:

int array1[some size][some size];

int main(){
int array2[somesize];int array3[somesize][somesize];
int NUM; /*This number is assigned some value*/
int i;int x; /*some integers that is within the sizes of the arrays*/
.
.
.
array2[i-1]+=array1[i][x]; "invalid types 'bool[int]' for array subscripts" MY ERRORS
array1[1][array3[x][i]+1]+=NUM; "array1 undeclared (first use this function)". MY ERRORS
.
.
.
}

Thanks in advance for your time,

why don't you post the code that actually gets the errors. What you posted is what you want to do but not necessarily what you actually did. I know what you are attempting on line 11 can be done because I've done that quite a few times too.

Aight, here is it is. I am basically writing a poker hand recognition program that basically tells me what hand I have. You can make out what the variables mean for yourself as they are straight forward.

int flush[4][14];
int player_cards[2][2];
int board_cards[4];   

int i;int x;

void update(int start, int showing){
   for (i=start;i<showing;i++)
   {  if(board_cards[i]<13)
         {flush[1][board_cards[i]+1]++;/*<---PROBLEM*/
           total[board_cards[i]]++;}
.
.
.
}

I am trying to keep track of what cards are showing so I can later analyze the possible hands. The flush array is set to 0 so if this functino is called then whatever card is showing is marked in the flush array by adding 1. This is updated as cards are shown (flop... turn... river).

Later on in my code when I am checking for a flush possiblity I receive the invalid type error even:

int checkf[3]

for(i=1;i<5;i++)
   {  for(x=1;x<14;x++)
         checkf[i-1]+=flush[x][i];} /*<---PROBLEM*/

I hope this is enough information!! Thanks again.

In the first program, last line, total is undefined.

and flush is undefined in the second program. Without seeing the entire program I can't tell you why.

Alright well heres the whole program minus a few things. Some parts are incompleted I am simply trying to debug my problems. As of now the ones previuosly mentioned are my only ones.

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int flush[4][14];
int player_cards[2][2];   
int shuffled_deck [51];
int board_cards[4];
int player_hand[5];

int total[13];

int card;
int i;int x;
int showing;
   
void shuffle_deck(){
   int dealt_cards[51];int equal;
   
   for (i=0;i<52;i++)dealt_cards[i] = -1;

   for (i=0;i<52;i++)
   {  equal = 0;
      while(equal!=1)
      {  shuffled_deck[i] = rand()%52;
         if (dealt_cards[shuffled_deck[i]]!=0)
         {  dealt_cards[shuffled_deck[i]]++;equal=1;}}}
}  

void update(int start){
   for (i=start;i<showing;i++)
   {  if(board_cards[i]<13)
         {flush[1][board_cards[i]+1]++;total[board_cards[i]]++;} 
      else if((board_cards[i])<26)
         {flush[2][board_cards[i]%13+1]++;total[board_cards[i]%13]++;}
      else if(board_cards[i]<39)
         {flush[3][board_cards[i]%26+1]++;total[board_cards[i]%26]++;}
      else
         {flush[4][board_cards[i]%39+1]++;total[board_cards[i]%39]++;}
         
      if((board_cards[i]%39)==0)
         {flush[4][14]++;total[13]++;}
      else if((board_cards[i]%26)==0)
         {flush[3][14]++;total[13]++;}
      else if((board_cards[i]%13)==0)
         {flush[2][14]++;total[13]++;} 
      else if(board_cards[i]==0)
         {flush[1][14]++;total[13]++;}}
} 

void deal_cards(){
   card = 0;   
   for (i=1;i<3;i++)
   {  for (x=1;x<3;x++)
         player_cards[x][i] = shuffled_deck[card++];}    
}

void flop(){
   for (i=0;i<3;i++)board_cards[i]=shuffled_deck[card++];
   showing = 3;update(0);  
}

void turn(){
   board_cards[3]=shuffled_deck[++card];
   showing++;update(3); 
}

void river(){
   board_cards[4]=shuffled_deck[++card];
   showing++;update(4); 
}

void add_subtract(int player,int NUM){
   for(i=1;i<3;i++){  
      if(player_cards[player][i]<13)
         {flush[1][player_cards[player][i]+1]+=NUM;total[player_cards[player][i]]+=NUM;} /*PROBLEM*//*PROBLEM*//*PROBLEM*/
      else if((player_cards[player][i])<26)
         {flush[2][player_cards[player][i]%13+1]+=NUM;total[player_cards[player][i]%13]+=NUM;}
      else if(board_cards[i]<39)
         {flush[3][player_cards[player][i]%26+1]+=NUM;total[player_cards[player][i]%26]+=NUM;}
      else
         {flush[4][player_cards[player][i]%39+1]+=NUM;total[player_cards[player][i]%39]+=NUM;}
      
      if((player_cards[player][i]%39)==0)
         {flush[4][14]+=NUM;total[13]+=NUM;}
      else if((player_cards[player][i]%26)==0)
         {flush[3][14]+=NUM;total[13]+=NUM;}
      else if((player_cards[player][i]%13)==0)
         {flush[2][14]+=NUM;total[13]+=NUM;} 
      else if(player_cards[player][i]==0)
         {flush[1][14]+=NUM;total[13]+=NUM;}}
}

bool check_straight(int temp[],int player_hand[]){
   int straight=0;
   for(i=14;i>0;i--)
   {  if(temp[i]!=0&&temp[i-1]!=0)straight++;
      else straight=0;
      if(straight==5)break;}
   
   if(straight==5)
   {  player_hand[5]=temp[i+3];
      player_hand[4]=temp[i+2];
      player_hand[3]=temp[i+1];
      player_hand[2]=temp[i];
      player_hand[1]=temp[i-1];
      return true;}
}

bool check_two_pair(int temp[],int player_hand[]){
   int pair=0;
   for(i=13;i>-1;i--)
   {  if(temp[i]==1&&temp[i]>player_hand[1])
      {  player_hand[1]=i;}
      else if(temp[i]==2&&pair==0)
      {  player_hand[5]=i;
         player_hand[4]=i;
         pair++;}
      else if(temp[i]==2&&pair==1)
      {  player_hand[3]=i;
         player_hand[2]=i;
         pair++;}} 
   if(pair==2)return true;
}

bool check_trips(int temp[],int player_hand[]){

}

bool check_pair(int temp[],int player_hand[]){

}

bool check_full_house(int temp[],int player_hand[]){

}

void poker_hand(int player,int player_hand[]){
   int check[13];int checkf[3];int suit=-1;int temp[13];
   
   bool straight_flush=false;
   bool quads=false;
   bool full_house=false;
   bool flush=false;
   bool straight=false;
   bool trips=false;
   bool two_pair=false;
   bool pair=false;
   bool high_card=false;
   
   
   for(i=0;i<4;i++)checkf[i]=0;
   
   for(i=0;i<14;i++)check[i]=total[i];   
   check[player_cards[player][0]%13]+=1;  
   check[player_cards[player][1]%13]+=1; 
   
   add_subtract(player,1);
   
   for(i=1;i<5;i++)
   {  for(x=1;x<14;x++)
         checkf[i-1]+=flush[x][i];}/*PROBLEM*//*PROBLEM*/
   
   if(checkf[0]>=5)suit=1;
   if(checkf[1]>=5)suit=2;
   if(checkf[2]>=5)suit=3;
   if(checkf[3]>=5)suit=4;
   
   if(suit!=-1)
   {  for(i=0;i<14;i++)temp[i]=flush[suit][i+1];}/*PROBLEM*//*PROBLEM*/
   
   straight_flush = check_straight(temp,player_hand);
   straight = check_straight(total,player_hand);  
   pair = check_pair(total,player_hand);
   pair = check_two_pair(total,player_hand);
   
   add_subtract(player,-1);
}

void initialize_hands(){
   for (i=1;i<3;i++)
   {  for (x=1;x<3;x++)
        player_cards[x][i] = -1;}

   for (i=0;i<5;i++) board_cards[i] = -1; 
     
   showing=0; 
   
   for (i=1;i<15;i++)
   {  for (x=1;x<5;x++)
         flush[x][i]=0;}   /*PROBLEM*/
}

int main(){
   srand((unsigned)time(0));
   
   initialize_hands();
   
   shuffle_deck();
   deal_cards();
   
   flop();
   
   for (i=0;i<52;i++)
       cout<<shuffled_deck[i]<<endl;
   
   
   cin>>i;   
   return 0;
}

The main problem with that is that the symbol flush is also declared in std namespace. When you have using namespace std; you include everything in the entire namespace in your program. That is one of the dangers of using that statement. If you replace that with only want you need in your program than the ambiguous symbol error will go away

#include <cstdlib>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::string;

// rest of code here

Now, after getting past that, the next error is on the line you noted: and the reason is that you defined another symbol named flush that hid the original array named [/b]flush[/b] (see line 146) Delete the bool declaration on line 146 because it isn't used anyway.

This question has already been answered. Start a new discussion instead.