code for controls

I have been trying to write code for moving controls..
please look at the code and tell me wat i have done wrong.
necessary header files have been included

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
  while(i<79&&j<25)
{
if(kbhit())
{
ch=getch();

 if(ch=='d'||ch=='D')                          // for right
 {            gotoxy(i,j);
   cout<<"*";
    k=i;
   gotoxy(k-1,j);
   cout<<" ";
  i++ ;

  } ;



if(ch=='a'||ch=='A') // for left
{
int w=i;
gotoxy(w-1,j);
cout<<"*";
gotoxy(w,j);
cout<<" ";
i--;
}
if(ch=='s'||ch=='S')                // for down
{
gotoxy(i-1,j+1);
cout<<"$";

e=j;
gotoxy(i-1,e);
cout<<" ";

j++;
}
if(ch=='w'||ch=='W')       // for up
{
int f=j+1;
gotoxy(i-1,j-1);
cout<<"*";
gotoxy(i-1,f-1);
cout<<" ";
 j--;
 }
Last edited on
Cleaned it up a bit for you.

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
while(i<79&&j<24)
{
	if(kbhit())
	{
		ch=getch();

		if(ch=='d'||ch=='D')
 		{
			gotoxy(i,j);
   			cout<<" ";
			++i;
   			gotoxy(i,j);
   			cout<<"*";
  		}

		if(ch=='a'||ch=='A') 
		{
			gotoxy(i,j);
			cout<<" ";
			i--;
			gotoxy(i,j);
			cout<<"*";
			
		}
		
		if(ch=='s'||ch=='S')                
		{
			gotoxy(i,j);
			cout<<" ";
			j++;
                        gotoxy(i,j);
			cout<<"*";
			
		}
		
		if(ch=='w'||ch=='W')
		{
                        gotoxy(i,j);
			cout<<" ";
			j--;
			gotoxy(i,j);
			cout<<"*";
 		}
	}
}
Topic archived. No new replies allowed.