Password validation cpp | Sololearn: Learn to code for FREE!

0

Password validation cpp

https://sololearn.com/coach/76/ There is 2 errors🙏🏻 https://code.sololearn.com/c7xWGrSVMxb9/

8/24/2020 5:52:33 AM

Mohamad Nourigohar

7 Answers

New Answer

+3

thank you for your attention

+4

#include <iostream> using namespace std; int main() { int a=0,b=0,c=0,d=0; string pswrd; getline(cin,pswrd); a=pswrd.length(); for(; b<a; b++){ if(pswrd[b]=='$'||pswrd[b]=='&'||pswrd[b]=='@'||pswrd[b]=='%'||pswrd[b]=='#'||pswrd[b]=='*'||pswrd[b]=='!'){ c++;} if(pswrd[b]=='1'||pswrd[b]=='2'||pswrd[b]=='3'||pswrd[b]=='4'||pswrd[b]=='5'||pswrd[b]=='6'||pswrd[b]=='7'||pswrd[b]=='8'||pswrd[b]=='9'||pswrd[b]=='0'){ d++;} } if(c>=2 && d>=2 && a>=7){ cout << "Strong"; }else { cout << "Weak"; } return 0; } // Mohamad Nourigohar Why are you checking for characters? The password length must be atleast 7 it's written in description.

+4

Minor mistakes committed by Mohamad Nourigohar : 1) The challenge didn't asked for how many capital/small letters does the password have but rather the length of the whole password(including symbols and numeric) must be atleast 7. 2) It is always a good practice to initialize variables when you declare them with 0 or any valid value. 3) [Not mistake but an improvement] Why use those bunch of ifs statement when you can use some syntactic sugar to achieved the same in just few lines. Anyway, the code is perfect and hope you've learnt something new and as always "happy learning" 😇

+2

M̷o̷u̷l̷i̷ 🇮🇳 that doesn't matter as per the challenge descriptions or logic. But yeah, you're right those small typos.

+1

https://code.sololearn.com/c7xWGrSVMxb9/?ref=app

0

Mohamad Nourigohar I can't find any error in your code.

-2

problem is in code coach