String Variable Question

So I’m having issue with the following line of code:

*if (((gender = "female") and (preference = "both")) or ((preference = "women")))

Basically this code has to do with romance, but if you choose male as your gender, the choice will still pop up. I’ve already tried doing it different ways (putting gender last) but it’s still not working. I’m guessing it has something to do with the and/or part but I don’t know.

Any thoughts?

2 Likes

Let me put the code in a single line…

*if (((gender = "female") and (preference = "both")) or ((preference = "women")))

There you go.


Hmm.

I don’t see any condition that represents gender = male. Are you sure with the code?

On another matter,

FWIW, the checks’ arrangement doesn’t matter, if any at all.

1 Like

Whelp. But yea, that’s why I’m so confused. It literally says that it’s for females only so I have absolutely no clue what’s wrong. That’s why I thought maybe the order mattered.

1 Like

Oh, I thought this

is an intended effect.


By the way, does straight man (gender = male, pref = women) should be able to pick the option or not?

2 Likes

The parentheses are off. If a male likes women, it will trigger the preference for women clause, because it’s an “or.”

There’s a better way to do it, but I’m too tired to play with the parens now. Try this:

*if gender = "female"
  ((*if preference = "both") or (preference = "women"))
    text
4 Likes

Ah I think I see what you mean, so does it complete negate the gender = female part? And should I have it on two different lines to fix it?

1 Like

I edited my post above with a way to work it. Hope it works for you!

1 Like

Would it work as a single line if structured like this?
*if ((gender = "female") and ((preference = "both") or (preference = "women")))

2 Likes

Ahh! That actually worked. I have no idea how but I don’t really care!! Thank you!

1 Like

I’m having a hard time describing in words how and why I did what I did. That’s probably a sign I should go to bed. Instead, I made a picture to demonstrate how I was interpreting the problem, and what I was trying to do with my suggestion. Because who needs sleep, really?

parentheses_are_trouble

Doing my best to put it into words anyway (and hoping these words make any sense at all):

I tried make sure both sides of the “or” part of the condition would combine with the “and” part. To do this, I first made sure they were enclosed within a set of parentheses they didn’t share with anything else. This is the “((preference = "both") or (preference = "women"))” section.

I then added the “and” part outside of the parentheses for the “or” part (I put it in front, but it should work exactly the same at the back). That’s the “(gender = "female") and” section. Finally, I wrapped the whole mess in one last layer of parentheses to make sure CS couldn’t leave anything out by accident.

I feel there’s a significant chance these words have just made everything even more confusing, and I apologize. I hope they help despite my misgivings.

7 Likes

That actually makes so much sense and the image definitely helped. Thank you for taking the time out to explain that to me.

4 Likes