(Help)C++ how to call Arrays out of separate function

My problem is creating a function or storing them in a function but calling upon those arrays to bring into main. So I created the function and started off with my smallest array to see if I can get it to work first before bringing anything else over. Sadly it did not work I brought array and its contents over to the function and tried to call up that specific array and bring into the main. Here is what I did in pictures. The code I have below is just to show I created the function stored one of my smaller arrays in it and tried but failed to call upon it in the main. The program I felt was too big to put the whole thing in.

1
2
3
4
5
6
7
8
9
void instructions();

void InitializeVars();

void HeroInventory();

void PlayGame();

int main()


1
2
3
4
5
6
7
8
9
10
void InitializeVars()
{

   string WrongChoice[1]; 
   
                
   WrongChoice[0] = "Sorry that is not a valid input please chose 1 or 2: "; 

}


1
2
3
4
5
6
7
8
9
10
11
     while( choice != 1 && choice != 2) 
      
      { 
      
      
        cout << InitializeVars(WrongChoice[0]) << endl; 
        
     
        cin >> choice; 
        
      } 
Last edited on
Better use a std::vector instead of an array. See:

http://www.cplusplus.com/reference/vector/vector/?kw=vector

In order to use values from another function, that function may return that object. Or you provide an existing object as a parameter.
I really rather not switch everything to vectors. But just in case how would I call the vector out of a function and into the main I still don't really get how to do that.
Topic archived. No new replies allowed.