Question: I'm making a Pay Calculator for my companies employees. It takes Federal Tax, Social Security Tax, and Medicare Tax into consideration. However, some of the employees are independent contractors and do not pay certain taxes. Thus all of these taxes are on their separate switch button. I'm having trouble making the "if" statements for these switches, because I have never done a switch before. I'm hoping someone could lead me in the right direction! 

Code:

```
- (IBAction)calculateButtonPressed:(UIButton *)sender
{
    float dailyRate = [self.dailyRateTextField.text floatValue];
    float daysWorked = [self.daysWorkedTextField.text floatValue];
    float grossPay = dailyRate * daysWorked;
    float taxRate = .72;
    float ssRate = .938;
    float medRate = .9855;
    float netPay = grossPay * taxRate * medRate * ssRate;
    self.dailyRateTextField.text = [NSString stringWithFormat:@"$%.2f", dailyRate];
    self.netIncomeTextField.text = [NSString stringWithFormat:@"$%.2f", netPay];
    self.grossIncomeTextField.text = [NSString stringWithFormat:@"$%.2f", grossPay];

    if (fedTaxSwitchOutlet.on) {}

    if (!fedTaxSwitchOutlet.on) {}

    if (ssTaxSwitchOutlet.on){}

    if (!ssTaxSwitchOutlet.on) {}

    if (medTaxSwitchOutlet.on) {}

    if (!medTaxSwitchOutlet.on) {}

    }    

}

```

Does anyone know how I would do an equation in the "if" statement? Like if the Medicare Tax Switch is turned off I still would like the app to calculate the persons the social security tax and the federal tax.

Answer: 
As Stefan suggested, I'd introduce `Purchase` nodes that have relationships with the products and also store the purchase value in that node. That way you can restrict the query to the purchases, without having to go deeper to reach the products.

```
(:Agent)-[:made]->(:Purchase {date: XXX, value: XXX})-[:HAS]->(:Product)

```

Let's say we have a relationship `:WORKS_FOR` to relate children agents to their parents:

```
(a1:Agent)-[:WORKS_FOR]->(a2:Agent)

```

This simple query will give you the sum of purchases every agent has done him/herself, without taking into account his children:

```
MATCH (parent:Agent)-[:MADE]->(p:Purchase) RETURN parent.name, sum(p.value)

```

Now, if you additionally want to take into account the purchases of the agents' children you can do:

```
MATCH (parent:Agent)-[:MADE]->(p:Purchase) WITH parent, sum(p.value) AS own_value OPTIONAL MATCH (parent)<-[:WORKS_FOR*]-(child:Agent)-[:MADE]->(pc:Purchase) RETURN parent.name, own_value + sum(pc.value) as total_value

```
I guess you frequently need to calculate the sum of all purchases bewteen a specfic agent A and product P. If so it might be beneficial to introduce a a `total_purchases` relationship between A and P holding the sum. Whenever you add a new purchase, make sure to update the existing `total_purchases` relationship.

Another thing to consider is if the current approach of having `purchases` relationships hides some domain concepts. I can think of agents placing multiple orders. Each order contains multiple items - which is what you currently refer using the `purchases` relationship. So the order would be a node holding e.g. date connected to 1) the agent and 2) to the products. 

In general everything being a concept on its own or having an identity should be modelled as a node.