Aug 23, 2013 at 2:49am UTC
1 2 3 4 5 6
if (Staff.name != "Phillip" and Staff.name != "Mac" )
cout << "Name Error!" << endl;
else if (Staff.ID != 303337 and Staff.ID != 303338)
cout << "ID Error!" << endl;
else if (Staff.name != "Treasure" and Staff.name != "Jackpot" )
cout << "Password Error" << endl;
The last condition does not make sense to me
Last edited on Aug 23, 2013 at 2:50am UTC
Aug 23, 2013 at 4:39am UTC
Ooops that was a typo...Here is the real corrections:
1 2 3 4 5 6
if (Staff.name != "Phillip" || Staff.name != "Mac Malloni" )
cout << "Name Error!" << endl;
else if (Staff.ID != 303337 || Staff.ID != 303338)
cout << "ID Error!" << endl;
else if (Staff.password != "Treasure" || Staff.password != "Jackpot" )
cout << "Password Error" << endl;
Its still not outputting the desired effect.
Last edited on Aug 23, 2013 at 5:03am UTC
Aug 23, 2013 at 4:48am UTC
What is the exact output and the desired output?
Aug 23, 2013 at 5:11am UTC
If the user doesn't enter the correct information name, ID, or password then an error message is suppose to appear. Such as "Name Error"
"ID Error"
"Password Error"
.
The problem is, when I run the program, the error message appears despite the fact that I entered the correct information.
Aug 23, 2013 at 5:17am UTC
Oh! silly me.
Replace all the ||s with &&s. Reason it out in your head and you will know why. :)
Aug 23, 2013 at 5:17am UTC
Have you tried the code I suggested? This should have solved your problem
Aug 23, 2013 at 5:23am UTC
is "and" meant to be psuedocode?
Just wondering... ;p
Aug 23, 2013 at 5:55am UTC
Thanks for the help @Smac89. Sorry, I didn't notice your sample code was different from mine.
I realize why the add operator works. But why didn't my code work? Sorry if this is a silly question
Aug 23, 2013 at 6:25am UTC
@keskiverto: I stand corrected. (Though you didn't include ciso646)
The AND operator works. You used the OR operator
Aug 23, 2013 at 6:54am UTC
Whenever you find yourself having to deal with double negatives, always use
and
When you find yourself dealing with double positives always use
or
1 2 3
if ( a != b and a != c ) assert ( a == a );
if ( a == b or a == c ) assert ( a != a );
Last edited on Aug 23, 2013 at 6:54am UTC
Aug 23, 2013 at 5:52pm UTC
Thanks for all your help @Smac89, I will keep that in mind next time.