Intermittent Math Errors

Intermittent Math Errors

I have a simple app which works perfectly over and over, then, randomly, it makes a math error. I'm talking about simple addition and subtraction. Maybe it is a processing time issue. Perhaps the next entry is happening while the last one is still processing? Regardless, it makes our scorecards unreliable in the eyes of the users. Help would be appreciated...

Our techs use the app/form to walk through a checklist. The result is a number of "passed" items and a percent passed score. Basically, at random times, the counter gets out of sync. 

The users are typically logging results on an iphone where it appears more prone to happen. But in troubleshooting it, I can replicate this on the desktop. Specifically, there are 21 items in the checklist. Most of the time it increments and decrements perfectly. Then suddenly it doesn't, and the counter is permanently out of sync. E.g. 20 items will be checked and the counter will say 17. 

To reproduce it on the desktop I can click a few fields as passed and then click one field on and off in succession and eventually the counter will become incorrect. 

The code is simple - I start with a total number of items and track passes by incrementing or decrementing a counter. I have tried it with both decimal and integer fields and the results are exactly the same. I use decision (boolean) fields to check off an item as passed. The code for each field is as follows. 

// *********************************************************
//
itemspassed = input.Total_Items_Passed_Decimal;
itemstotal = input.Total_Items_Decimal;
if (input.Brakes)
{
    itemspassed = (itemspassed  +  1);
}
if (!input.Brakes)
{
    itemspassed = (itemspassed  -  1);
}
input.Total_Items_Passed_Decimal = itemspassed;
input.Score_decimal_percent = (100.0  *  itemspassed  /  itemstotal);