Expertsystemen

 

Adding a formula to a repeated section

Let’s focus on how you can repeat formulas. For this, you will have to go back to the main branch of the decision tree.

One of the pieces of information asked in this decision tree is the monthly salary of the employee. With formulas, we can easily add up all of these individual salaries. Before we have asked any salary, our total should be zero (0). Then, after each time we acquire an individual salary, we will add this to the total.

In xxllnc Expertsystemen, we will first add a formula called totalsalary to hold the total salary and to which we will add up all salaries of our employees. We will initialise it to zero (0):

Total salary is initially zero
Total salary is initially zero

Now we have the formula called totalsalary, copy and paste this formula to the same Actions panel, so that we have two identical formulas. Now we will edit the second formula in the Actions window so that it will accumulate all salaries into the total salary.

Open our second totalsalary formula. In the text box called Formula, we’ll add the salary of each individual employee to this total. In order to do this, we type the following:

totalsalary + gperson[counter].salary.salary

As in the picture below:

Total salary plus an individual salary
Total salary plus an individual salary

The correct order of the Actions list

Now, make sure the initial formula (setting it to zero) comes before the repeated section indicated by the repeat item. And move the second formula so that it is within the repeated section, but after the graph call in which we ask our employees’ details, so between the call graph item and the until end condition.

the actions panel
the actions panel

Showing the total salary

Now let’s show this total salary to the end-user: Make a separate ending node, titled summary. In this node, add a text that refers using caret syntax to the totalsalary formula in the node employees:

Total salary: ^{employees.totalsalary}
Presenting the total salary summary
Presenting the total salary summary

Now if you run the model and add a few random salaries, you should see that they will be added up correctly and shown afterwards.