The Cellar  

Go Back   The Cellar > Main > Technology
FAQ Community Calendar Today's Posts Search

Technology Computing, programming, science, electronics, telecommunications, etc.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 11-24-2010, 01:41 AM   #23
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
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 10:24 AM.


Powered by: vBulletin Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.