My program runs a three dimensional maze (3x3x3 = 27 locations) it has a start room exit room and code room all in a loop so no two are the same location, the start and exit rooms show up on the run compiled program but the code room does not cout? However if run from the executable created it shows all three rooms, re-running of the compiled shows the code room still missing? It compiles fine apart from this and I am not sure if somehow I've coded it wrong, although then it should have thrown up compile errors? (Lost)! Here's the code
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int direction;
int location, old_location;
int startRoom;
int endRoom;
int codeRoom;
do {
time_t now;
time(&now);
srand(now);
startRoom = rand() % 26;
endRoom = rand() % 26;
codeRoom = rand() % 26;
system ("cls");
}while (startRoom == endRoom||startRoom == codeRoom||endRoom == codeRoom); //while start, code or end match = to re-allocate
location = startRoom;
int map[3][9][10] =
{
{
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{99, 9, 3, 99, 99, 99, 1, 99, 99, 99}, // 0
{99, 10, 4, 99, 0, 99, 2, 99, 99, 99}, // 1
{99, 11, 5, 99, 1, 99, 99, 99, 99, 99}, // 2
{99, 12, 6, 99, 99, 99, 4, 99, 0, 99}, // 3
{99, 13, 7, 99, 3, 99, 5, 99, 1, 99}, // 4
{99, 14, 8, 99, 4, 99, 99, 99, 2, 99}, // 5
{99, 15, 99, 99, 99, 99, 7, 99, 3, 99}, // 6
{99, 16, 99, 99, 6, 99, 8, 99, 4, 99}, // 7
{99, 17, 99, 99, 7, 99, 9, 99, 5, 99} // 8
},
{
{99, 18, 12, 0, 99, 99, 10, 99, 99, 99}, // 9
{99, 19, 13, 1, 9, 99, 11, 99, 99, 99}, // 10
{99, 20, 14, 2, 10, 99, 99, 99, 99, 99}, // 11
{99, 21, 15, 3, 99, 99, 13, 99, 9, 99}, // 12
{99, 22, 16, 4, 12, 99, 14, 99, 10, 99}, // 13
{99, 23, 17, 5, 13, 99, 99, 99, 11, 99}, // 14
{99, 24, 99, 6, 99, 99, 16, 99, 12, 99}, // 15
{99, 25, 99, 7, 15, 99, 17, 99, 13, 99}, // 16
{99, 26, 99, 8, 16, 99, 99, 99, 14, 99} // 17
},
{
{99, 99, 21, 9, 99, 99, 19, 99, 99, 99}, // 18
{99, 99, 22, 10, 18, 99, 20, 99, 99, 99}, // 19
{99, 99, 23, 11, 19, 99, 99, 99, 99, 99}, // 20
{99, 99, 24, 12, 99, 99, 22, 99, 18, 99}, // 21
{99, 99, 25, 13, 21, 99, 23, 99, 19, 99}, // 22
{99, 99, 26, 14, 22, 99, 99, 99, 20, 99}, // 23
{99, 99, 99, 15, 99, 99, 25, 99, 21, 99}, // 24
{99, 99, 99, 16, 24, 99, 26, 99, 22, 99}, // 25
{99, 99, 99, 17, 25, 99, 99, 99, 23, 99} // 26
}
};
old_location = location;
cout << "You awake to find yourself locked in a grid of rooms" << endl;
cout << "\n" << "Directions of travel are 2 for N, 6 for E, 8 for South, 4 for West," << endl;
cout << "1 for Up, 3 for DOWN" << "\n" << endl;
cout << "starting location = room " << location << endl;
cout << "Final exit = room " << endRoom << endl;
cout << "Code for final exit room = room " << codeRoom << "\n" << endl; //= no show on compiled version?????????
cout << "Enter your direction to travel?" << endl;
while (location !=endRoom)
{
cin >> direction;
location = map[0][location][direction];
if(location == 99)
{
cout << "Incorrect move...!!!... Enter direction again." << endl;
location = old_location;
}
else
{
cout << "Your at location " << location << endl;
old_location = location;
if (location == endRoom)
cout << "You've found the exit" << endl;
}
}
system("PAUSE");
return 0;
}
I know windows and using system, bad, bad!
Any help much appreciated on this confusing issue.
Regards Leppie.