What is wrong with my code for the following question ? My code is in comment section.It is showing error in 4 and 13 test case. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is wrong with my code for the following question ? My code is in comment section.It is showing error in 4 and 13 test case.

You're interviewing to join a security team. They want to see you build a password evaluator for your technical interview to validate the input. Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '

#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong

2nd Jan 2021, 1:55 PM
Mahak
9 Answers
+ 2
Mahak Garg First, you dont need to count uppercase letters and lowercase letters and whitespace. You just need the number of symbols and digits. Second, You forgot the second else statement outside the for loop. If you have more question, feel free to ask. https://code.sololearn.com/c8zzCz71SlSA/?ref=app
2nd Jan 2021, 2:14 PM
noteve
noteve - avatar
+ 2
Your first code structure looked like this. if True if True //strong else //weak This should be: if True if True //strong else //weak else //weak
2nd Jan 2021, 2:17 PM
noteve
noteve - avatar
+ 1
#include <iostream> #include <string> using namespace std; int main() { int l = 0, u = 0,d = 0, sy = 0, sp = 0,i; string s; cin>>s; int l1 = s.length(); if(l1>=7) { for(i=0;i<l1;i++) { if(islower(s[i])) { l+=1; } else if(isupper(s[i])) { u+=1; } else if(isdigit(s[i])) { d+=1; } else if(isspace(s[i])) { sp+=1; } else if(s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '
#x27; || s[i] == '%' || s[i] == '&' || s[i] == '*' || s[i] == '_') { sy+=1; } } if(l>=1 && u>=1 && d>=2 && sy>=2 && sp>=0) { cout<<"Strong"; } else { cout<<"Weak"; } } }
2nd Jan 2021, 1:57 PM
Mahak
+ 1
I got your point 《 Nicko12 》 Thanks for your help.
2nd Jan 2021, 2:21 PM
Mahak
+ 1
Hmm. Ok although Im not very familiar with Java. But yeah fine maybe I can help somehow.
2nd Jan 2021, 2:39 PM
noteve
noteve - avatar
+ 1
@《Nicko12》 I have completed my java code so if you want you can leave it. 🙂
2nd Jan 2021, 2:59 PM
Mahak
+ 1
Mahak Garg Glad you solved it. I cant figure it out though, not familiar with syntax. 😅
2nd Jan 2021, 3:01 PM
noteve
noteve - avatar
+ 1
That's alright 🙂
2nd Jan 2021, 3:06 PM
Mahak
0
《 Nicko12 》 Can you please help me out with my java code as well for the same question ?
2nd Jan 2021, 2:39 PM
Mahak