help me with bug in program

its really weird if you look in the code it should display a | in the corner of
the screen but it doesn't and if you move left twice (hit "a" then enter then repeat)it shows 2 of them one in a correct position one not if you go up from the spawn position (hit "w" then enter) it is in a correct position if you go over once it displays it in the correct position.

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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;




int main()
{
	string command ;
	
	string save;	
	 
	//menu

	 menu:

	 cout << " say newgame to start or, load to load new game " << endl;

	 cin >> command;
	 if (command == "newgame" );	 
	 
	 if (command == "load" ) goto load;	 
	 
	 system("cls");

	 //end

	dstart:

	//stats

	int hp = 100;

	int maxhp = 100;

	int xp = 0;

	//end
	    
     //spawn pos.
	 
     int x = 5;
     int y = 5;

     //end

	 //save
	 save:
		
		
		
	//end

	start:

     //map

	 char world [10] [10] = {0};

	 world [6] [6] = '|';

	 if (x == 8) x = 3;

	 if (x == 2) x = 7;

	 if (y == 8) y = 3;

	 if (y == 2) y = 7;
     
     //end

     //avatar	

     world[x][y] = '@' ;

     //end	 
 
	 //death

	 if (hp < 1) 
	 {
		 cout << "you died" << endl << endl;
		 
		 goto dstart;
	 }

	 //end
     
	 //graphics script

     cout << world[x+2][y+1];
     cout << world[x-1][y+1];
     cout << world[x][y+1];
     cout << world[x-1][y+1];
     cout << world[x-2][y+1];
     cout << endl;
     cout << world[x+2][y];
     cout << world[x+1][y];
     cout << world[x][y];
     cout << world[x-1][y];
     cout << world[x-2][y];
     cout << endl;
     cout << world[x+2][y-1];
     cout << world[x+1][y-1];
     cout << world[x][y-1];
     cout << world[x-1][y-1];
     cout << world[x-2][y-1];
     cout << endl <<endl;
	 cout << "Health:" << hp << endl << endl;
     //end

     //movement script

     cin >> command;
	 cout << endl;
     if (command == "w" && world[x][y+1] != '|') y = y + 1;
	 if (command == "s" && world[x][y-1] != '|') y = y - 1;
     if (command == "d" && world[x-1][y] != '|') x = x - 1;
     if (command == "a" && world[x+1][y] != '|') x = x + 1;
	 if (command == "save") goto save;

     //end

	 system("cls");

     goto start;

	load:
		
		
		
	goto start;
     
	return 0;

}

don't use goto use sub-functions
Last edited on
I don't think that's my problem
They may not be the problem but they are bad to use. same with system("anything") and if the problem occurs with 'a' it is probably something to do with line 123. And to be honest it looks like your a and d are backwards shouldnt a go to the left and d go to the right? and try using x++, x--, y++, y--, or even x += 1, x -= 1, y += 1, y -= 1 instead of the x = x + 1, ect....
well other than the problem I said it works so...
its not with the a just the array you should compile it and try to do what I said in it because it is really weird and I honestly cant find the source of the problem
Topic archived. No new replies allowed.