For the last couple of hours I have been sitting with a calculator in my mouth and do not understand how the formula should look.

How to express the problem correctly from a mathematical point of view - I do not know, therefore, I will explain as a student of grade 3B:

We get a value from -much to + a lot. If the value is <250, then we return 2. If the value is> 380, then we return 8. And if the value is 250 <X <380, then we need to return ~ something between 2 and 8 ~, for example, if X = 260, then we return ~ 2.3, if X = 300, then we will return ~ 4.9, if X = 360, then we will return ~ 7.6.

Threw a minimal example:

static void Main(string[] args) { for (int i = 240; i < 390; ++i) Foo(i); Console.ReadLine(); } static void Foo(int num) { const int minPoint = 250; const int maxPoint = 380; const double change = 2; const double change2 = 8; double result; if (num < minPoint) result = change; else if (num > maxPoint) result = change2; else result = ??; Console.WriteLine(result); } 

I hope that the question is clear.

  • How are the values ​​distributed? Evenly? - Enikeyschik February

1 answer 1

 result = (num - minPoint)*(change2 - change)/(maxPoint-minPoint) + change;