This is probably really easy, but I’m lost on how to “make sure” it is in this range..
So basically we have class Color and many functions to implement from it.
this function I need is:
Effects: corrects a color value to be within 0-255 inclusive. If value is outside this range, adjusts to either 0 or 255, whichever is closer.
This is what I have so far:
static int correctValue(int value)
{
if(value<0)
value=0;
if(value>255)
value=255;
}
Sorry for such a simple question ;/
I agree with the other answers, with one modification; this should be an else-if statement. There is no need to test if the value is over 255 if you already know it is less than 0