I see. There are, of course, tons of ways to do everything in computers. Likely Brad will show up and tell you how to do this in one line of code. But in the meantime, here's how I would think through it:
"Once you have all the fail scenarios then failure is no longer possible and you will always get an encounter. "
So would it make sense that there's X% chance something's going to happen (failure or encounter)? Then I might start it that way (this is more pseudo-code than actually syntax-correct code):
RAND = 1d100
IF RAND less than 50 THEN
BEGIN END
Then you've just got one big block that only happens when the encounter is possible. If there's a 100% chance of either the encounter or the fail, you just leave that out. Then, inside that BEGIN block, how do you decide if there's an encounter or failure? If that's a % chance, that's another IF inside the block -- but you've also got to decide if there can be a failure. Personally, I'd use one variable for failure. The value would range from 0 to 3, indicating the number of failures.
So, if there's a 25% chance here of getting a failure (if allowed):
RAND = 1d100
IF RAND less than 25
BEGIN
IF NUMFAILURES less than 3
BEGIN give a failure here (and increment NUMFAILURES) END
ELSE
BEGIN give random encounter here END
END
ELSE
give a random encounter here
My brain isn't quite there right now, but I think that would do it, if that's what you want to do. Yeah, there's some repetition in there, but that's a side effect of the AND not working right.