2015-05-29 87 views
-1

對不起,如果我聽起來像一個白癡或我的代碼本身是壞的,但我需要所有的幫助,我可以得到。很多人編寫了這些代碼,但我不想看他們的代碼,基本上是複製和粘貼。所以這裏的問題是,當我嘗試運行這個程序時,它給了我那個標識符_TCHAR是未定義的,並且在第20行給出了「< signed/unsigned mismatch」的警告。再次,我很樂意獲得任何幫助。C++幫助,密碼驗證程序

#include <iostream> 
#include <cstring> 

using namespace std; 


int main(int argc, _TCHAR* argv[]) 

{ 
    const int size = 1000; 

    char password[size]; 

    int count; 

    int times1 = 0; 

    int times2 = 0; 

    int times3 = 0; 
    cout << "Please enter your password: "; 
    cin.getline(password, size); 


    if (strlen(password) < 6){ 

     cout << "Not valid, your password should be atleast 6 letters"; 

    } 

    for (count = 0; count < strlen(password); count++) 
    { 

     if (isupper(password[count])) { 

      times1++; 

     } 

     if (islower(password[count])){ 

      times2++; 

     } 

     if (isdigit(password[count])){ 

      times3++; 

     } 

    } 

    if (times1 == 0) { 

     cout << "Invalid, the password should contain atleast one uppercase letter"; 

    } 

    if (times2 == 0) { 

     cout << "Invalid, the password should contain atleast one lowercase letter"; 

    } 

    if (times3 == 0) { 

     cout << "Invalid, the password should contain atleast one digit"; 

    } 



    cin.get(); 
    return 0; 
} 
+1

謝謝@drescherjm用於固定後 – Edwin

+1

'_TCHAR'是微軟的發明。它不是一個標準的C++類型。 – PaulMcKenzie

+1

'_TCHAR'應該在'windows.h'中。嘗試包括該文件。 – Martin

回答

1

在while循環中(從times1 = 0,times2 = 0,times3 = 0到cin.get()之前)包裝所有內容。使用一個名爲類似validPass的bool變量並初始化爲true。當其中一項要求失敗時,只要使validPass = false。在而應該是同時(validPass == FALSE){...}

#include "stdafx.h" 
#include <iostream> 
#include <cstring> 

using namespace std; 


int main() 

{ 
    const int size = 1000; 

    char password[size]; 

    int count; 

    bool validPass; 
    do 
    { 
     validPass = true; 
     int times1 = 0; 

     int times2 = 0; 

     int times3 = 0; 
     cout << "Please enter your password: "; 
     cin.getline(password, size); 


     if (strlen(password) < 6){ 

      cout << "Not valid, your password should be atleast 6 letters"; 
      validPass = false; 
      continue; 

     } 

     for (count = 0; count < strlen(password); count++) 
     { 

      if (isupper(password[count])) { 

       times1++; 

      } 

      if (islower(password[count])){ 

       times2++; 

      } 

      if (isdigit(password[count])){ 

       times3++; 

      } 

     } 

     if (times1 == 0) { 

      cout << "Invalid, the password should contain atleast one uppercase letter"; 
      validPass = false; 
      continue; 

     } 

     if (times2 == 0) { 

      cout << "Invalid, the password should contain atleast one lowercase letter"; 
      validPass = false; 
      continue; 

     } 

     if (times3 == 0) { 

      cout << "Invalid, the password should contain atleast one digit"; 
      validPass = false; 
      continue; 

     } 

    } while (!validPass); 

     cin.get(); 
    return 0; 
} 
+0

你真了不起,非常感謝你的幫助,我終於可以安息了。這是我最後的額外學分課程,現在我希望教授喜歡它,並在班上給了我102% – Edwin