0

I have a two layer logic problem, and limited programming skills so I made a problem that I do not know how to solve, outline of what does not work is below.

I need to enable the user (me) to choose which combination of algorithms to use. A combination of algorithms may be applied (not just one at a time, or any), so I cannot use an 'or' operator. I need to be able to use multiple algorithms simultaneously to get a solution, while ignoring algorithms that are not in use.

public bool useAa (get; set;)
public bool useBb (get; set;)
public bool useCc (get; set;)
public bool useDd (get; set;)


public bool? doaa { get; set; }
public bool? dobb { get; set; }
public bool? docc { get; set; }
public bool? dodd { get; set; } 
public bool? doee { get; set; } 

if ((x >0) & (aa == true))
                {
                    doaa = true;
                }
                else doaa = false;

                if (useAa == false)
                {
                    doaa = null;
                }


if ((y >0) & (bb == true))
                {
                    dobb = true;
                }
                else dobb = false;

                if (useBb == false)
                {
                    dobb = null;
                }
                
if ((z >0) & (cc == true))
                {
                    docc = true;
                }
                else docc = false;

                if (useCc == false)
                {
                    docc = null;
                }               
                
if ((e >0) & (ee == true))
                {
                    doee = true;
                }
                else doee = false;

                if (useEe == false)
                {
                    doee = null;
                }   

...

if ((doaa.HasValue && doaa == true) & (dobb.HasValue && dobb == true) & (docc.HasValue && docc == true) & doee.HasValue && doee == true))
            {
                holy_grail_found (stuff);
            }
  • 2
    Welcome to StackOverflow! Please read [ask]. It's great that you've supplied code, but please make sure that it's a [mcve]: in particular, it's very important that it *compiles* (your code won't), and that it can be easily *run* by other people to let them see your problem – canton7 Feb 05 '21 at 17:24
  • 3
    Note that `doaa == true` is the same as `doaa.HasValue && doaa == true` – canton7 Feb 05 '21 at 17:26
  • It's not clear what you are trying to do. Also google the difference between `&` and `&&`. – Buh Buh Feb 05 '21 at 18:24
  • Hey Victor, what do you mean by "skip Booleans"? and in addition to what canton7 said. doaa is nullable so if it was null and you call doaa.HasValue this will cause an exception. if you want to use doaa.HasValue make sure that you have doaa != null. – Mamdouh Feb 05 '21 at 18:59
  • @canton7 regarding doaa.HasValue, I was of the impression that this will return "true" only if it is not "null". Thus, the reason why I have it is my attempt at disabling the doaa boolean if useAa = false. No this does not work so I would like to know how can I set this up in a way that does. – Victor Major Feb 05 '21 at 19:43
  • @Buh Buh I had a look at boolean operators, but I could not understand how & and && could make a difference in my problem. As to what I am trying to do is to for example disable doaa boolean states if useAa = false and only consider the doaa "true" or "false" states if useAa = true. – Victor Major Feb 05 '21 at 19:48
  • @Mamdouh I want any boolean in the do** group to be ignored if use** = false if ((doaa.HasValue && doaa == true) & (dobb.HasValue && dobb == true) & (docc.HasValue && docc == true) & doee.HasValue && doee == true)) thus for example if doaa.HasValue = false because useAa = false I want doaa state to be ignored. In this example there are 24 combinations of algorithms that can be used here: if ((doaa.HasValue && doaa == true) & (dobb.HasValue && dobb == true) & (docc.HasValue && docc == true) & doee.HasValue && doee == true)) I need to deal with that programmatically. – Victor Major Feb 05 '21 at 20:00
  • @VictorMajor regrading & , &&. Man I hope you googled it before asking but anyway check this https://stackoverflow.com/questions/5537607/usage-of-versus – Mamdouh Feb 05 '21 at 21:45

0 Answers0