Stuck on checking the criteria for a password.

Fixed.
Last edited on

If the user can type spaces, then you need to use the function getline instead of the >> operator because the >> operator is delimited by spaces.
See an example here:
http://www.cplusplus.com/reference/string/string/getline/


(didnt add the #include stuff at the top):

It's best to include the #include stuff as long as its standard library headers, as it makes it easier for others to quickly run your code to help you.

A self-contained check-for-spaces function would look like this:
1
2
3
4
5
6
7
8
9
bool has_spaces(string s)
{
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == ' ')
            return true;
    }
    return false;
}

__________________

Something else to add: The way I would go about this problem is to have something like this:
(pseudo code)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

ask user to input password
do
{
    int error_code = password_test(password);

    if (error_code) {
        print error_message[error_code];
        ask for password entry again
    }
    else {
        password is acceptable
    }
    
} while (not good password);

If that doesn't make sense, don't worry about it, it's just suggestion.
Last edited on
Topic archived. No new replies allowed.