okay, so iv tried to pass the argument, of allowing my array from main to work in my function buy_items()...the only thing is i must now enter something in, where i have stated "missing part of code here" iv tried a few things but they dnt work, So hopefully someone here knows?
#include <iostream>
#include <string>
usingnamespace std;
void buy_items(); // the missing part of the code is here, within the parenthesis right?
int main()
{
constint MAX_ITEMS = 10;
string player_inventory[MAX_ITEMS];
int item;
player_inventory[item++] = "shoe";
cout << player_inventory;
cout << "\n\nnow show the same array in a different function using arguments";
buy_items(); //oh and also missing here too
int pause;
cin >> pause;
}
void buy_items(string player_inventory[], int item)
{
cout << player_inventory;
cout << "add extra item to the same array from main() and show it in this function";
player_inventory[item++] = "hat";
cout << player_inventory;
}
in main() so the scope of this array is inside the main only.
If you want to use it in some other function then you need to pass to the function. First declare
1 2 3 4 5
void buy_items(string arr[]){
// do something withe array
}
then in the main call the function by passing the array as the argument