Hi, I have the four following variables, and the values of these variables need to be within a set a threshold of the optimal value. The only way I can think of at the moment to validate them is with the following code. If anyone could suggest an alternative way that would be great:

I could put the values in an array, and go through each one. However, this is more time consuming. Additionally, the number of variables required is always going to be 4, so there is not really a maintainability advantage in using an array.Code:`const int OPTIMAL_VAL = 5;`

const int THRESHOLD_VAL = 1;

int iA = 4, iB = 5, iC = 5, iD = 6;

if((OPTIMAL_VAL - THRESHOLD_VAL >= iA && iA <= OPTIMAL_VAL + THRESHOLD_VAL) &&

(OPTIMAL_VAL - THRESHOLD_VAL >= iB && iB <= OPTIMAL_VAL + THRESHOLD_VAL) &&

(OPTIMAL_VAL - THRESHOLD_VAL >= iC && iC <= OPTIMAL_VAL + THRESHOLD_VAL) &&

(OPTIMAL_VAL - THRESHOLD_VAL >= iD && iD <= OPTIMAL_VAL + THRESHOLD_VAL))

{

//WHATEVER

}

Thanks.