View Single Post
Old 11-29-2010, 10:59 AM   #30
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
This is, of course, semantics, but no, it doesn't.

I had a solution to design: how to test for two conditions.

I figured, while either one is false, correct that one.


What could be simpler, or easier to understand?
Quote:
while !(a) or !(b)
{
if !(a)
call (a)

if !(b)
call (b)
}
You could remove both if statements altogether. With the side effects that a() and b() have, this code would be equivalent:

Quote:
while !(a) or !(b)
{
}
This is because !(a) is actually calling a(). If the test fails, then the password is changed (the side effect in question). This loop will run until the password makes it through both tests without being changed.

Quote:
What I don't understand is why you guys find what I did confusing. I used regular, human logic.
A big one is that you seem to think that the a's are different in:
Quote:
if (!a)
call a()
They are the same. Whatever is done in one will be done in the other.
Quote:
What are the undesirable "side effects" of my functions??? My functions didn't do anything but return a value until I moved some parts of main function into them so you guys could understand the elegant simplicity of my while/if/if loop.

I could put it back this way:

Code:
while ((!passLength(password)) || (!containDigit(password))) 
{
if (!passLength(password))
{
cout << "Passwords must be at least 6 characters long" << endl;
cout << "Please enter a password1: ";
cin.getline(password, SIZE);
(passLength(password)); //(a)
}
 
if (!containDigit(password))
{
cout << "Passwords must include at least on digit (1-9)" << endl;
cout << "Please enter a password2: ";
cin.getline(password, SIZE);
(containDigit(password)); //(b)
} 
}
Does that help you to understand that I designed it this way on purpose? This is not accidental, there are no "side effects" ...
(assuming there is no longer a getline in the tests, the lines I crossed out can be removed)
That is completely different. The tests no longer can change the password. That is logically a good program, though it could be more efficient.

Moving the parts of main() into the tests did not result in an equivalent program. You could not with this programn (as I did above with the other one) remove the entire contents of the while loop and have an equivalent program.
__________________
_________________
|...............| We live in the nick of times.
| Len 17, Wid 3 |
|_______________| [pics]
Happy Monkey is offline   Reply With Quote