char ch;
string username;
rc1:ch=getch();
while(1)
{
if(ch>=33&&ch<=126)
{
username.push_back(ch);
cout<<ch;
ch=getch();
}
elseif(ch==8)//8 is backspace ascii code
{
if(username.length()==0)
{
goto r1;
}
username.erase(username.length()-1,1);
cout<<' ';
r1: ch=getch();
}
elseif(ch==13)//13 is enter ascii code
{
if(username=="")//just don't let cursor go down when press enter while username don't have value
{
goto rc1;
}
goto r2;
}
else
{
ch=getch();
}
}
r2:
Look at the line number 9 when i press (uppercase letter p) it show letter P normally,but when i press (arrow down key) it also show letter P.It mean (Letter P ascii) and (arrow down key ascii) is the same(80).So when i press (arrow down key) it will transfer letter P to (variable : username),I don't want it.I want it's nothing when i press (arrow down key).