Suppose I have a variable x (double) that lies between 0 and 100. If x is in any of the intervals (0+10*n,5+10*n), with n (int) =0,...,9, then I return n, otherwise I break. I was thinking of doing this
bool test = false;
int k;
for(int i=0; i<10; i++){
if((0+10*i)<x<(5+10*i)){
k = i;
test = true;
}
}
if(test) return k;
else break;
would this be correct? If so, is there any other way that avoids loops?