Why is my password validation code not WORKING!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why is my password validation code not WORKING!?

#include <iostream> #include <string> bool isValidPassword(const std::string& password) { int numCount = 0; int specialCharCount = 0; for (char c : password) { if (isdigit(c)) { numCount++; } else if (c == '!' || c == '@' || c == '#' || c == '

#x27; || c == '%' || c == '&' || c == '*') { specialCharCount++; } } return numCount >= 2 && specialCharCount >= 2 && password.length() >= 7; } int main() { std::string password; std::cout << "Enter the password: "; std::cin >> password; if(isValidPassword(password)){ std::cout << "Strong" << std::endl; } else { std::cout << "Weak" << std::endl; } return 0; }

10th Dec 2023, 7:56 AM
Sammy Maingi
Sammy Maingi - avatar
4 Answers
+ 2
Do not paste code into the description. Link your code. Format your code. Make it readable.
10th Dec 2023, 10:31 AM
Lisa
Lisa - avatar
+ 1
Can you link me to your code on your profile
10th Dec 2023, 1:45 PM
Sickfic
Sickfic - avatar
+ 1
In case this is a sololearn task, pay close attention to the output: Only output as described in the instructions – nothing additional, no input prompts.
10th Dec 2023, 10:20 PM
Lisa
Lisa - avatar
0
I tried it and ran into no problems, everything seems to work as intended. Did multiple tests all with different conditions of input
10th Dec 2023, 9:26 PM
Sickfic
Sickfic - avatar