# Calculate Additive Value (Tracking Progress From 0 - 100)

I am trying to calculate an additive value for required tasks only in my application and am having a hard time with the math.

In my application I have a total of 13 tasks that are optional (represented below by $O$). I will know how many are going to be executed before execution begins. I have a varying number of required tasks that is also known before execution begins represented below by $R$.

When each optional task is executed it increments total progress by $1$. I need to calculate how much to add when required tasks complete.

So a basic coding example:

int Progress = 0;

if (t.Optional)
Progress++;
else
}


The current calculation for the additive value is: $$\mathbf{A = \left(\frac{R}{100 - O}\right) \cdot 100}$$

This is just not correct and I am trying to understand what I am doing wrong here.

EDIT

So after receiving help through comments and looking over my code, I figured out that the issue here was multiplying by 100 for the additive value before adding it to progress, also, since this value can be greater than $0$ but less than $1$ it needed to be stored in a temporary variable before assigning it back to the total progress in the end.

THANK YOU

Thank you all for your help, and also to the administrators for applying the appropriate tags. I wish I could make this post clearer for future readers, and if anyone has any ideas please feel free to let me know. This boiled down to simply overlooking an extra step that wasn't needed.

• do you know the total number of tasks to be executed before the first task runs? Apr 11, 2018 at 13:07
• Yes, sorry, I forgot to add that value. Updating question. Apr 11, 2018 at 13:09
• Impossible to understand... Apr 11, 2018 at 13:09
• You say that tasks 01,02 and 03 are optional. Thus, how to compute the progress if we do not know what happens ? Apr 11, 2018 at 13:10
• I am trying to calculate the value to add for 't'. Apr 11, 2018 at 13:10

To solve for the additive value (represented by $A$) simply divide the number of required tasks (represented by $R$) by $100$ minus the number of optional tasks (represented by $O$), and this will give you the percentage each required task is responsible for.

$$\mathbf{A = \frac{R}{100 - O}}$$

Since $A$ is a decimal type with a value that can be greater than $0$ but less than $1$, you'll have to keep track of the total percentage as a decimal type; then convert it to integer before assigning it to the progress control. So in coding terms:

int OptionalTasks = 13;
int Progress = 0;
double tempProgress = 0;

if (t.Required)
tempProgress += requiredPercentage;
else
tempProgress++;

Progress = (int)tempProgress;
}


I ended up using @Vasya's answer in the comments above and just adding it to the existing percentage (represented by $P$) after summing all tasks (represented by $T$). $$\mathbf{A = \frac{100}{T}}$$ $$\mathbf{P = P + A}$$

In the end this ended up being the more ideal approach as less math was involved. The number of optional tasks still has to be calculated before the math can be performed, but it allows the additive value to be constant across all tasks, thus reducing confusion for future developers.

int OptionalTasks = 13;