View Single Post
Old 11-24-2010, 12:41 AM   #25
Happy Monkey
I think this line's mostly filler.
 
Join Date: Jan 2003
Location: DC
Posts: 13,575
Quote:
Originally Posted by Flint View Post
I'm interested to know why you think this is; as I cannot conceive of a logic where this makes sense. Aside from the fact that this isn't what happens. I'm just interested to hear your reasoning.
Say you call containDigit("abc")
Code:
    int index = 0;
    int length = strlen(password);
    
    for (index = 0; index < length; index++ )
    {
        if (isdigit(password[index]))
            return true;
    }
It gets through these steps, and gets here:
Code:
        cout << "Passwords must include at least on digit (1-9)" << endl;
        cout << "Please enter a password: ";
        cin.getline(password, SIZE);
The user enters "abc1".
And then:
Code:
        return false;
The password is now "abc1", and containDigit() returned false.

You don't see the problem in your execution because your while loop corrects for the behavior of the test functions. But if you tested the functions individually, you would see it.

Quote:
Originally Posted by Flint View Post
This code only "calls" passLength IF passLength is false.

What exactly do you mean by "IF passLength is false"? A function can only be false if it is called and executed.

Unlike the solutions graciously suggested by Pete Zicato and Happy Monkey, in my code I do not require a superfluous bool variable. I use the bool function to evaluate itself. Maybe this is "wrong" but it works.
My first suggestion also doesn't need the bool, without the side effects in the test functions.
__________________
_________________
|...............| We live in the nick of times.
| Len 17, Wid 3 |
|_______________| [pics]
Happy Monkey is offline   Reply With Quote