Using radios to set conditions in OBject Class

Digimstr

Member
Joined
Sep 26, 2014
Messages
7
Programming Experience
Beginner
Hello all I am working on a problem that I am using radios to set conditions then trying to add values for an equation to return back to form;

My code looks like this to determine what value to set my data member to but I am getting 0 instead of defined amounts


public void SetShipSurcharge(double _shSurCharge)
{

if (shDesintation != "AK-ALASKA" || shDesintation != "HI-HAWAII")
shSurCharge = 0;

else if (shOption == "Standard Shipping")
shSurCharge = STAND_SURCHARGE;
else if (shOption == "Express Shipping")
shSurCharge = EXPRESS_SURCHARGE;
else
shSurCharge = SAMEDAY_SURCHARGE;
} //End SetShipSurcharge

any help would be great thanks
 
This is your issue:
if (shDesintation != "AK-ALASKA" || shDesintation != "HI-HAWAII")
Think about what that is actually doing. Consider a few possible examples for `shDesintation` and how that line behaves for them.
 
Unless I am mistaking the if (shDesintation != "AK-ALASKA" || shDesintation != "HI-HAWAII") forces everything but AK and HI to receive a surcharge of zero then I am trying to install surcharges based off the level of shipping requested. ShDestination and shOption are passed through the constructor and I am trying to load shSurCharge with the appropriate value based off the level that the user selects.

If am I am wrong I am not sure what I need to do to fix it.
 
You're forgetting the English language just because you're programming. You do know the difference between "and" and "or", right? Let's say that I have 5 people in front of me. They are 20, 22, 24, 26 and 28 years of age. If I say "if you're not 22 years old or you're not 26 years then stand behind me", what would you expect to happen? Obviously the people who are 20, 24 and 28 years old will stand behind me. The person who is 22 is not 24 years old so they will stand behind me, while the person who is 26 is not 22 years old so they will stand behind me also. That statement didn't exclude anyone at all.

How about some simple Boolean logic?

True OR True = True
True OR False = True
False OR True = True
False OR False = False

That's fairly obvious, right? So, the only way that your `if` statement is going to evaluate to False is if both conditions are False. Can you think of any value of shDesintation that will make both those conditions False? The only way the first one is going to be False is if shDesintation is equal to "AK-ALASKA" and the only way the second one will be False is if shDesintation is equal to "HI-HAWAII". How is one variable going to be equal to two different values at the same time?
 
So it should be something like if (shDesintation != "AK-ALASKA" && shDesintation != "HI-HAWAII") then?

I should have been able to see this I will try this and see if it happened the way it should now thanks.
 
Back
Top Bottom