因此该代码应该验证用户输入的密码。密码必须至少6个字符,它应至少有一个大写字母,并且至少有一个小写字符,并且其中至少应有一位数字。我尝试这样做,当我运行它时,它要求我输入密码,但如果我输入的密码无效,则不会显示任何内容。
#include "stdafx.h"
#include <iostream>
#include <cstring>
using namespace std;
int _tmain(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){
"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) {
"Invalid, the password should contain atleast one uppercase letter";
}
if (times2 == 0) {
"Invalid, the password should contain atleast one lowercase letter";
}
if (times3 == 0) {
"Invalid, the password should contain atleast one digit";
}
cin.get();
return 0;
}
答案 0 :(得分:5)
那是因为当密码错误时你忘了打印任何东西:
"Not valid, your password should be atleast 6 letters";
应该是
cout << "Not valid, your password should be atleast 6 letters";
答案 1 :(得分:0)
好的,你只需要使用std :: cout&lt;&lt; “”无效,密码应包含至少一个数字“&lt;&lt; std :: endl以输出您想要的消息。