Ascii characters in output

Hi,

This code is outputting this symbol
and I do not know why.

Its making me really frustrated.

Here's the code:

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
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <iostream>
#include <time.h>

using namespace std;

int randomtile();

void main()
{
	srand(time(NULL));

	char map[20][20][20];
	char ftile;
	int upd = 0;
	char ud;

	for(int n=0; n < 20; n++)
	{
		for(int m=0; m < 20; m++)
		{
			for(int s=0; s < 20; s++)
			{

				if(map[n][m][s-1] == ' ')
				{
					map[n][m][s] = ' ';
					break;
				}

				if(map[n][m][s-1] == '*')
				{
					map[n][m][s] = ' ';
					break;
				}
				
				ftile = randomtile();

				map[n][m][s] = ftile;
			}
		}
	}

	while(true){

		system ("cls");

		for(int n=0; n < 20; n++)
		{
			for(int m=0; m < 20; m++)
			{
					cout << map[n][m][upd] << ' ';
			}
			cout << endl;
		}

		cout << upd << endl;
		cin >> ud;
		switch (ud)
		{
			case 'u':
				upd++;
				break;
			case 'd':
				upd--;
				break;
		}
		if(upd < 0)
		{
			upd = 0;
		}

	}
}

int randomtile()
{
	char tile;

	tile = rand() % 20 + 1;

	switch (tile) 
	{
		case 1:
			tile = '^';
			break;
		case 2:
			tile = '^';
			break;
		case 3:
			tile = '^';
			break;
		case 4:
			tile = '^';
			break;
		case 5:
			tile = '*';
			break;
		case 6:
			tile = '*';
			break;
		case 7:
			tile = '*';
			break;
		case 8:
			tile = '*';
			break;
		case 9:
			tile = '*';
			break;
		case 10:
			tile = '*';
			break;
		default:
			tile = '*';
	}

	return tile;
}


PS: I know using system("whatever") is "bad". This project is just for fun, so I don't care.
map[n][m][s-1] is out of bounds when s == 0.
I tried adding && s > 2 to the if statement and it still had the same output.
Last edited on
Topic archived. No new replies allowed.