The @ can't move to left

The @ can move to right but not to left.
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
#include<iostream>
#include "windows.h"
#include<string>

using namespace std;

bool loop = true;

void update(int px, string dir){
	if(dir=="right"){
		for(int i=1; i<41; i++){
			if(px==i){
				cout << "@";
			}else{
				cout << " ";
			}
		}
	}else if(dir=="left"){
		for(int i=40; i>0; i--){
			if(px==i){
				cout << "@";
			}else{
				cout << " ";
			}
		}
	}
}

int x=1;

int main(){
	while(loop==true){
		system("pause>nul");
		if(GetAsyncKeyState(VK_RIGHT)){
			int fx = x+x;
			if(fx>41){
				return 0;
			}else if(fx<0){
				return 0;
			}else{
				system("cls");
				x++;
				update(x,"right");
			}
		}else if(GetAsyncKeyState(VK_LEFT)){
			int fx = x-x;
			if(fx>41){
				return 0;
			}else if(fx<0){
				return 0;
			}else{
				system("cls");
				x--;
				update(x,"left");
			}
		}
	}
	return 0;
}
Please don't create new threads for nearly identical problems/code:
http://www.cplusplus.com/forum/general/121153/
No it's not the same problem. I also found out the problem but I don't know the solution of it.
The @ disappear when it goes left.
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
#include<iostream>
#include "windows.h"
#include<string>

using namespace std;

bool loop = true;

void update(int px, string dir){
	if(dir=="right"){
		for(int i=1; i<41; i++){
			if(px==i){
				cout << "@";
			}else{
				cout << " ";
			}
		}
	}else if(dir=="left"){
		for(int i=40; i<0; i--){
			if(px==i){
				cout << "@";
			}else{
				cout << " ";
			}
		}
	}
}

int x=1;

int main(){
	while(loop==true){
		system("pause>nul");
		if(GetAsyncKeyState(VK_RIGHT)){
			int fx = x+x;
			if(fx>41){
				return 0;
			}else if(fx<0){
				return 0;
			}else{
				system("cls");
				x++;
				update(x,"right");
			}
		}else if(GetAsyncKeyState(VK_LEFT)){
			int fx = x-x;
			if(fx>41){
				return 0;
			}else if(fx<0){
				return 0;
			}else{
				system("cls");
				x--;
				update(x,"left");
			}
		}
	}
	return 0;
}
Topic archived. No new replies allowed.