### Need Help w/Arrays

Can someone explain to me how arrays are supposed to work? I put them down but all I get is zero when I compile the program. How do I get the actual array produce the numbers and such?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158`` ``````#include #include #include #include #include using namespace std; const int ROOMS = 30; const int MAX_ARROWS = 7; const int MAX_BATS = 5; const int MAX_PITS = 5; /* game array [ number of arrows ][ player ][ wumpus ] */ int gameArray[3]; /* rooms array */ int roomArray[ROOMS][ROOMS]; /* bats array */ int bats[MAX_BATS]; /* pits array */ int pits[MAX_PITS]; // function prototypes void instructions(); void menu(); void printMemory(); void setup(); int getRandomRoom(); void createMaze(); void placeWumpus(); void placePlayer(); void placeHazards(); bool checkBats(int); bool checkNearBats(int); bool checkPits(int); bool checkNearPits(int); bool checkWumpus(int); bool checkNearWumpus(int); bool checkPlayer(int); int main() { int choice; const int INSTRUCTIONS = 1, BEGIN = 2, EXIT = 3; do { menu(); cin >> choice; if (choice == INSTRUCTIONS) { instructions(); } else if (choice == BEGIN) { printMemory(); } else if (choice == EXIT) { return 0; } else { cout << "You MUST choose an option between 1 and 3." << endl; } } while(choice < INSTRUCTIONS || choice > EXIT); return 0; } void instructions() { cout << "YOUR MISSION, SHOULD YOU DECIDE TO" << endl; cout << "ACCEPT IT, IS TO HUINT FOR THE WUMPUS" << endl; cout << "IN HIS CAVE. TO SUCCEED, YOU MUST SHOOT" << endl; cout << "IT WITH ONE OF YOUR 7 ARROWS." << endl; cout << "IF YOU SHOOT INTO A ROOM WHICH IS NOT" << endl; cout << "DIRECTLY CONNECTED TO YOURS, THE ARROW" << endl; cout << "WILL BOUNCE TO ONE OF THE ROOMS THAT" << endl; cout << "DOES CONNECT. THE BATS IN THE CAVE MAY" << endl; cout << "PICK YOU UP AND PLACE YOU IN A DIFFERENT ROOM" << endl; cout << "IF YOU ENTER A ROOM WHICH HAS A PIT" << endl; cout << "YOU WILL FALL INTO IT!" << endl; cout << "IF THE WUMPUS FINDS YOU OR YOU RUN OUT OF ARROWS " << endl; cout << "YOU WILL LOSE!!" << endl; } void menu() { cout << "\n\t\tMain Menu" << endl; cout << "1. Instructions" << endl; cout << "2. Begin" << endl; cout << "3. Exit" << endl; cout << endl; cout << "Enter Menu Selection:" << endl; } void printMemory() { gameArray[3]; cout << gameArray[3] << endl; roomArray[ROOMS][ROOMS]; cout << roomArray[ROOMS][ROOMS] << endl; bats[MAX_BATS]; cout << bats[MAX_BATS] << endl; pits[MAX_PITS]; cout << pits[MAX_PITS] << endl; }``````

Last edited on
`cout << gameArray[3] << endl;`
This is out of bounds.

`gameArray[3];`
This doesn't do anything at all.

This applies to all of your printMemory() function.

There's actually nowhere in your code where you actually do anything to these arrays. You declare them in global space, and that's it.
Topic archived. No new replies allowed.