So close (I think)! I've been working on this for some time now (on and off, coming back to it) and now I'm stuck. Hopefully there's not to much wrong with the coding of it, the compiler throws up lines 50 & 63 with errors?
Not to sure if I've got the array right [9][10][3], which way do these run?
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int direction;
int location, old_location;
int map[9][10][3] =
{
{
{
// 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
}
}
}; //compiler throws up initializer
location = 0;
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, 1 for UP, 3 for DOWN" << "\n" << endl;
cout << "starting location = room " << location << "\n" << endl;
cout << "Enter your direction to travel?" << endl;
while (location !=26)
{
cin >> direction;
location = map[location][direction]; //compiler throws up as invalid
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 == 26)
cout << "You've found the exit" << endl;
}
}
return 0;
}
As always, your help is well appreciated
Leppie