Someone explain me why this isn't working!
This program is supposed to put a "%" on the screen then move it around when the user presses keys.
a: left
s: right
w: up
z: down
It doesn't work. The program just puts another "%" right next to the other one.
#include <iostream.h>
#include <conio.h>
char key;
int x = 35, y = 18;
int main(){
key = getch();
for(;;){
gotoxy(x,y);
cout << "%";
getch();
switch(key){
case 'a':
x--;
break;
case 's':
x++;
break;
case 'w':
y--;
break;
case 'z':
y++;
break;
}
}
}
New code but still the same problem without % being repeated
#include <iostream.h>
#include <conio.h>
char key;
int x = 1, y = 1;
int main(){
key = getch();
for(;;){
clrscr();
gotoxy(x,y);
cout << "%" << flush;
getch();
switch(key){
case 'a':
cout << '\b'; --x;
break;
case 's':
cout << '\b'; ++x;
break;
case 'w':
cout << '\b'; --y;
break;
case 'z':
cout << '\b'; ++y;
break;
}
}
}
it worked!!! but a new question
How do i get rid of the annoying little _?