How do I remove nested if else conditions? I'm playing around with the concept of functional programming.
I have flattened the nested if statements and made by code more verbose.
The refactored code looks overly complicated.
What could be a simpler approach?
Nested Ifs
public static int Main(string[] args)
{
    int computer = 1;
    string brand = &quot;PC&quot;;

    if (computer &lt; 2)
    {
        if (brand != &quot;Apple&quot;)
        {
            // perform complex calculation 1
            Console.WriteLine(&quot;you don't own a Mac&quot;);
            return 0;
        }
        else
        {
            // perform complex calculation 2
            Console.WriteLine(&quot;you own less than 2 Macs&quot;);
            return 1;
        }
    }
    else
    {
        // perform complex calculation 3
        Console.WriteLine(&quot;you own two or pcs&quot;);
        return 2;
    }
}

Flattened Main
public static int Main(string[] args)
{
    int computer = 1;
    string brand = &quot;PC&quot;;

    return CalculatedResult = DetermineComputer(computer, brand);
}

Extension Methods
public static class extensions
{
    public static int ComplexCalc1(this bool val)
    {
        Console.WriteLine(&quot;you don't own a Mac&quot;);
        return 0;
    }
    public static int ComplexCalc2(this bool val)
    {
        Console.WriteLine(&quot;you own less than 2 Macs&quot;);
        return 1;
    }
    public static int ComplexCalc3(this bool val)
    {
        Console.WriteLine(&quot;you own greater than two pcs&quot;);
        return 2;
    }
    public static int ComplexCalc4(this bool val)
    {
        Console.WriteLine(&quot;Condition not accounted for&quot;);
        return -1;
    }

    public static bool IsLessThanTwo(int computer) =&gt; computer &lt; 2;

    public static bool IsApple(string brand) =&gt; brand == &quot;Apple&quot;;

    public static (Func&lt;bool, int&gt; func, bool result) IsLessThanTwoAndNotApple(this int computer, string brand)
        =&gt; (ComplexCalc1, IsLessThanTwo(computer) &amp;&amp; (IsApple(brand) == false));

    public static (Func&lt;bool, int&gt; func, bool result) IsLessThanTwoAndIsApple(this int computer, string brand)
        =&gt; (ComplexCalc2, IsLessThanTwo(computer) &amp;&amp; IsApple(brand));

    public static (Func&lt;bool, int&gt; func, bool result) Unaccountedfor(this int computer, string brand)
        =&gt; (ComplexCalc4, true);

    public static (Func&lt;bool, int&gt; func, bool result) IsGreaterThanTwoAndIsNotApple(this int computer, string brand)
        =&gt; (ComplexCalc3, (IsLessThanTwo(computer) == false) &amp;&amp; (IsApple(brand) == false));
}

Calculation
public static int DetermineComputer(int computer, string brand)
{
    var methodlist = new List&lt;(Func&lt;bool, int&gt;, bool)&gt;
    {
        computer.IsLessThanTwoAndNotApple(brand),
        computer.IsLessThanTwoAndIsApple(brand),
        computer.IsGreaterThanTwoAndIsNotApple(brand),
        computer.Unaccountedfor(brand)
    };

    var tupleResult = methodlist.Where(x =&gt; x.Item2 == true).Select(x =&gt;
        new {
            functor = x.Item1,
            result = x.Item2
        }).First();

    return tupleResult.functor(tupleResult.result);
}

Unit Tests
[DataRow(3, &quot;Apple&quot;, -1)]
[DataRow(2, &quot;Apple&quot;, -1)]
[DataRow(1, &quot;Apple&quot;, 1)]
[DataRow(0, &quot;Apple&quot;, 1)]
[DataRow(3, &quot;PC&quot;, 2)]
[DataRow(2, &quot;PC&quot;, 2)]
[DataRow(1, &quot;PC&quot;, 0)]
[DataRow(0, &quot;PC&quot;, 0)]
[DataTestMethod]
public void NestedIfs_Demo(int first, string second, int expected)
{
    int computer = first;
    string brand = second;

    var CalculatedResult = DetermineComputer(computer, brand);

    Assert.AreEqual(expected, CalculatedResult);
}
I'm assuming that computer and brand are meant to be function parameters, otherwise any kind of branching would be unnecessary.
Here's something that pretty much does what you want, assuming you just want messages that describe in clear english the quantity and brand of computers, and not necessarily have the exact messages used in your examples:
public static void Message(int quantity, string brand)
{
    Console.WriteLine(&quot;You own &quot; + quantity + &quot; &quot; + brand + (quantity !== 1 ? 's' : '');
}

The actual brand and quantities are variables that are inserted into the general message. If you want the message to be longer and use more variables, then you would probably want to create substrings to later be combined, for the sake of readability:
public static void Message(int quantity, string brand)
{
    string brandPlural = brand + (quantity !== 1 ? 's' : '');

    Console.WriteLine(&quot;You own &quot; + quantity + &quot; &quot; + brandPlural;
}
```