Color Calculation
-
Hello, I want to return a string color based on these 4 calculations. X = 25% 5.0% >= X >= -5.0% blue +15.0% >= X > +5.0% and -5.0% > X >= -15.0% yellow +25.0% >= X > +15.0% and -15.0% > X >= -25% green X > +25.0% and X < -25.0% red I am having trouble forming the logic. Thank you for the help.
-
Hello, I want to return a string color based on these 4 calculations. X = 25% 5.0% >= X >= -5.0% blue +15.0% >= X > +5.0% and -5.0% > X >= -15.0% yellow +25.0% >= X > +15.0% and -15.0% > X >= -25% green X > +25.0% and X < -25.0% red I am having trouble forming the logic. Thank you for the help.
Off the top of my head - untested! :)
int x = 25;
Color c = GetColor (x);public Color GetColor
(int x)
{
if ((x <= 5) && (x >= -5))
return Color.Blue;
if ((x <= 15) && (x >= -15))
return Color.Yellow;
if ((x <= 25) && (x >= -25))
return Color.Green;
return Color.Red;
}/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com