2016-07-30 83 views
-4
void password() 
{ 
int i=0, j; 
char str[30], ch; 
gotoxy (23,10); 
cout<< "Welcome to our project! \n"; 
delay (800); 
gotoxy (23,11); 
cout<< "Please enter the password = "; 
while ((ch=getch())!=13) 
{ 
ch=getch(); 
str[i]=ch; 
i++; 
clrscr(); 
gotoxy (20,20); 
cout<< "Enter Password = "; 
for (j=0; j<i; j++) 
cout<< "*"; 
} 
str[i]='\0'; 
if (strcmp(str,"script")!=0) 
{ 
cout<< endl; 
cout<< "Incorrect Password! \n"; 
cout<< "Access Denied! \n"; 
getche(); 
exit (0); 
} 
} 

我做了一段時間後,我遇到了一個問題。所以問題在於,當我編譯程序並運行它時,沒有任何錯誤。唯一的問題是,當它要求我輸入腳本的密碼時,我必須按每個字母TWICE並顯示一次(例如,密碼是TOLS,我必須像TTOOLLSS那樣按它,並顯示爲TOLS )。我該如何解決它?單擊字母兩次?

+2

你可能已經至少格式化代碼,如果你希望有人來幫助你完成家庭作業。 – bytecode77

+0

我不認爲「字母」意味着你的想法。此外,你應該停止在DOS模擬器上編寫20世紀80年代的原始「C++」。 –

回答

2

刪除行:

ch=getch(); 

,因爲你已經得到了該行的字符:

while ((ch=getch())!=13)