My assignment is to take in values that will create a maze, and then let the user traverse the maze by use of a stack to store values.
I thought I had it down to it working, but now it isn't doing what it should and then it stops after only moving a few places (the program just won't take in more values). As far as what I've discovered, it doesn't store the values correctly (which is probably what's messing up the program) and it does something weird when a person enters another value.
There are basically two functions that I'm worried about (cause it worked when those weren't there) so if anyone can find what's wrong and suggest how to fix it, I'd really appreciate it. I'll give you the two functions and the text file. If you want me to post the full code, I can but it's really long.
And here are some picture to show where the issues are.
Stores 2 values then stops
http://i21.photobucket.com/albums/b272/DemonGal711/Program%20Pic/test1.png
Stores 1 value, is suppose to pop it out and move back to previous spot (but doesn't), then stops
http://i21.photobucket.com/albums/b272/DemonGal711/Program%20Pic/test2.png
Not a valid response, doesn't have an issue until two valid values are entered (though I didn't show that cause the first two show that).
http://i21.photobucket.com/albums/b272/DemonGal711/Program%20Pic/test3.png
What my text file t.txt looks like
4 4
0 0 1 0
0 1 0 0
0 0 0 1
1 1 0 0
TWO FUNCTIONS
void ask (stack& s, int& x, int& y, cell **a, int r, int c, int& count)
{ char cDir[5] = {'U', 'D', 'L', 'R', 'B'};
int cVal[5] = {0, 0, 0, 0, 0};
int ran = 1;
char val;
cout << "Where would you like to move:\n";
goToPts (x, y, r, c, s, a, cVal);
cin >> val;
val = toupper(val);
for (int i = 0; i < 5; i++)
{ if (cDir[i] == val)
{ if (cVal[i] == 1) ran = 0; } } // END FOR
if (ran == 1) { cout << "That was not a valid direction. Please enter a valid direction.\n\n\n"; }
else
{ s.push(val);
count++;
switch (s.top())
{ case 'L':
if (s.prev() == 'L') a[x][y].replace = "\xC4";
if (s.prev() == 'U') a[x][y].replace = "\xD9";
if (s.prev() == 'D') a[x][y].replace = "\xBF";
y--;
break;
case 'R':
if (s.prev() == 'R') a[x][y].replace = "\xC4";
if (s.prev() == 'U') a[x][y].replace = "\xC0";
if (s.prev() == 'D') a[x][y].replace = "\xDA";
y++;
break;
case 'U':
if (s.prev() == 'R') a[x][y].replace = "\xD9";
if (s.prev() == 'L') a[x][y].replace = "\xC0";
if (s.prev() == 'U') a[x][y].replace = "\xB3";
x--;
break;
case 'D':
if (s.prev() == 'R') a[x][y].replace = "\xBF";
if (s.prev() == 'D') a[x][y].replace = "\xB3";
if (s.prev() == 'L') a[x][y].replace = "\xDA";
x++;
break;
case 'B':
a[x][y].replace = " ";
switch (s.prev())
{ case 'L':
y++;
break;
case 'R':
y--;
break;
case 'U':
x++;
break;
case 'D':
x--;
break;
} // END switch
s.pop();
s.pop();
count--;
break;
} // END switch(val)
} // END else
} // END ask
void goToPts (int a, int b, int r, int c, stack s, cell **array, int check[])
{
if (a != 0 && array[a-1][b].num == 0 && s.top() != 'D')
{ cout << "U) Up \t";
check[0] = 1; }
if (a != r-1 && array[a+1][b].num == 0 && s.top() != 'U')
{ cout << "D) Down \t";
check[1] = 1; }
if (b != 0 && array[a][b-1].num == 0 && s.top() != 'R')
{ cout << "L) Left \t";
check[2] = 1; }
if (b != c-1 && array[a][b+1].num == 0 && s.top() != 'L')
{ cout << "R) Right\t";
check[3] = 1; }
if (b == c-1 && a == r-1) // if at the exit, allow them to go right
{ cout << "R) Right\t";
check[3] = 1; }
if (s.top() != 'E')
{ cout << "B) Back";
check[4] = 1; }
cout << "\n\n";
}