Program closing

During my moveLocation function sometimes the program will just randomly close and exit with code 0.
Any help as to why this is happening would be appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <string>
#include "Player.h"

using namespace std;

void moveLocation()
{
	Player User;

	bool safeDirection, findCreature, setCoords = false;
	int xCord = 0, yCord = 0;
	int rndmCreature;
	char direction;

	do{
		do{
		rndmCreature = (rand()% 3);
		findCreature = false;
		safeDirection = true;

		if (setCoords == false)
		{
			User.setXCord(User.getXCord());
			User.setYCord(User.getYCord());
		}
		setCoords = true;

		cout << "Where would you like to go? (N)orth, (E)ast, (S)outh, (W)est: ";
		cin >> direction;

		switch(toupper(direction))
		{
		case 'N':
			if (xCord > 0)
			{
				xCord = (xCord--);
				User.setXCord(xCord);
				
				if (rndmCreature == 1)
					findCreature = true;
				break;
			}
			else
			{
				cout << "You can not go further North.\n" << endl;
				safeDirection = false;
				break;
			}
		case 'E':
			if (yCord < 19)
			{
				yCord = (yCord++);
				User.setYCord(yCord);

				if (rndmCreature == 1)
					findCreature = true;
				break;
			}
			else
			{
				cout << "You can not go further East.\n" << endl;
				safeDirection = false;
				break;
			}
		case 'S':
			if (xCord < 19)
			{
				xCord = (xCord++);
				User.setXCord(xCord);

				if (rndmCreature == 1)
					findCreature = true;
				break;
			}
			else
			{
				cout << "You can not go further South.\n" << endl;
				safeDirection = false;
				break;
			}
		case 'W':
			if (yCord > 0)
			{
				yCord = (yCord--);
				User.setYCord(yCord);
				
				if (rndmCreature == 1)
					findCreature = true;
				break;
			}
			else
			{
				cout << "You can not go further West.\n" << endl;
				safeDirection = false;
				break;
			}
		default :
			cout << "Invalid input!\n" << endl;
			safeDirection = false;
		}
		}while (findCreature == false);
	}while (safeDirection == false);
}
Trying run Cout with all variables at the very top. Run the program 4-5 times and see if you see any strange results. It looks like it's probably a logic issue.
Topic archived. No new replies allowed.