Question: I have a few long switch cases in my program and I need to do both substraction and addition inside the switch cases. I want to write clean code as much as possible. I don't want to copy paste and change `+` sign to `-` sign manually everytime. How can I make this possible.

Here is sample;

```
private void SetWorkerBonus()
{
    switch (currentWorkerType)
    {
        case WorkerType.Gatherer:
            outputValue += currentWorkerCount * 1.1f;
            break;
        case WorkerType.Hunter:
            defenseAmount += currentWorkerCount * 1.06f;
            break;
        case WorkerType.Cook:
            foodAmount += currentWorkerCount * 1.03f;
            break;
        case WorkerType.Warrior:
            attackAmount += currentWorkerCount * 1.05f;
            break;
    }
}

```

I want my method to the same thing except with instead of `+` sing, with `-` sign.
For further clarification, when I set bonus for class and change the worker type, I want to substract the bonus I gave then give new type of bonus.

It doesn't matter if solution is with/out switch statement. I just want a clear solution for it.

Answer: 
You just need to pass a boolean flag to your SetWorkerBonus. If true you want to add, if false you want to subtract. Now with this flag initialize an integer variable to 1 or -1 and use this integer to multiply the calc made around *currentWorkerCount*

```
private void SetWorkerBonus(bool flagToAddOrSubtract)
{
    int multiplier = (flagToAddOrSubtract ? 1 : -1);
    switch (currentWorkerType)
    {

        case WorkerType.Gatherer:
            outputValue += ((currentWorkerCount * 1.1f) * multiplier);
            break;
        case WorkerType.Hunter:
            defenseAmount += ((currentWorkerCount * 1.06f) * multiplier);
            break;
        case WorkerType.Cook:
            foodAmount += ((currentWorkerCount * 1.03f) * multiplier);
            break;
        case WorkerType.Warrior:
            attackAmount += ((currentWorkerCount * 1.05f) * multiplier);
            break;
    }
}

```
well pass in a boolean variable as a parameter inside your function SetWorkerBonus and perform + or - based on ternary operator inside your switch statement

```
private void SetWorkerBonus(boolean isAdd)
{
    switch (currentWorkerType)
    {
        case WorkerType.Gatherer:
            outputValue = isAdd ? outputValue + currentWorkerCount * 1.1f : outputValue - currentWorkerCount * 1.1f
            break;
        case WorkerType.Hunter:
            defenseAmount = isAdd ? defenseAmount + currentWorkerCount * 1.06f : defenseAmount - currentWorkerCount * 1.06f;
            break;
        case WorkerType.Cook:
            foodAmount = isAdd ? foodAmount + currentWorkerCount * 1.03f : foodAmount - currentWorkerCount * 1.03f;
            break;
        case WorkerType.Warrior:
            attackAmount = isAdd ? attackAmount + currentWorkerCount * 1.05f : attackAmount - currentWorkerCount * 1.05f;
            break;
    }
}

```