2

I want to keep a variable in the range of [min, max]. For this purpose, I wrote this function:

void trapVar(int& var, int& min, int& max) {
   if(var < min) var = min;
   else if(var > max) var = max;
}

Is there any efficient or better (or any other implementation) way to realize this function? Maybe this implementation is the simplest one? You can comment on the coding style also.

Erdem Tuna
  • 500
  • 4
  • 18

0 Answers0