2015-05-29 67 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