Hey there. I have a coding assignment I'm supposed to complete for my Intro to C++ class.
I thought I had everything figured out, but for some reason, my code isn't working. It keeps giving incorrect answers.
The specifications for the program are as follows:
1. The password must contain at least one uppercase letter, one lowercase letter and a number.
2. It can’t have any punctuation character, accent or space.
3. The password must be 6 to 32 characters.
Input
The input contains several test cases and ends with EOF. Each line has a string S, corresponding to the password that is entered by the user at registration.
Output
The output contains a line, which can be "Senha valida.", if the password has all previously requested requirements, or "Senha invalida.", if one or more requirements aren’t met.
Here is the code I currently have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
#include <string>
#include <ctype.h>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
string password;
int b;
bool length=false, badChar=true, upper=false, lower=false, num=false;
while(getline(cin, password)){
b=password.length();
if(b <= 32 && b >=6){
length=true;
}
for(int a=0; a<1; a++){
if ((password[a]>=97 && password[a]<=122) || (password[a]>=65 && password[a]<=90) || (password[a]>=48 && password[a]<=57)){
badChar=false;
}
if (password[a]>=48 && password[a]<=57){
num=true;
}
if (password[a]>= 65 && password[a]<=90){
upper=true;
}
if (password[a]>=97 && password[a]<=122){
lower=true;
}
}
if(length==true && badChar==false && num==true && upper==true && lower==true){
cout << "Senha valida." << endl;
}
else {
cout << "Senha invalida." << endl;
}
}
return 0;
}
|
Is there anyway you all could tell me what is broken/wrong with the code? Thanks in advance.