Constrain variables

hi, I want to constran a veriable so it will allways be between tow values.
you know, if I add a number to said veriable and the new value ia higher then it
just has the constrained high value.
eg: try has a value of 5 but I dont want it to have a value more then 10 but if 6 is added to try 5+6=11?
I want try to stop at 10!
help.
ps I know if try > 10 :try = 10
I dont want to write that every time try is manipulated. :confused:

Hello.

I’m not sure what language you’re using, but in C you could create a function to constrain your variable for you:

int constrain(int x)
{
  if (x > 10)
    x = 10;
  if (x < 2)
    x = 2;
  return x;
}

You could then write your code like this:

try = constrain(try + 6);

- Ben

Thanks I think that will do.
Yes im programing in C.
well using a hammer realy. Bash away till it works. Ha Ha!
Thought maybe there was a way to define a veriable with a high and low value.
on a side line: you guys rock and your shits’ tha bomb!

Thanks for the praise! Unfortunately, C does not have built-in support for that kind of thing; you need to implement it yourself.

- Ben