C# Math equation help

I have a c# program with the following variables:

MinVoltage
MaxVoltage
MinValue
MaxValue

The VALUE could be %, Celcius, Fahrenheit Litres etc
The VOLTAGE could or could not be inverted (i.e. minVolt = 4.5 and maxVolt=0.5)

The user would set the min/max VALUE i.e.
MinValue:  0     (%)
MaxValue: 100 (%)


in the equation, i know the CURRENT VOLTAGE reading, and I need to translate that to the VALUE (in this example %)
The curve ball is that sometimes the min and max voltage is inverted, and other times its not


I need a C# (or basic maths equation to help output the VALUE)


In this example:
minVolt =  4.5
maxVolt = 0.5
minVal =    0      (%)
maxVal =   100  (%)

currentVoltage = 2.25

i.e. pseduo code is:
Function GetValueFromVoltage(decimal currentVoltage, decimal minVolt, decimal maxVolt, decimal minVal, decimal maxVal)
{
    boolean IsInverted = false;
  
    if (minVolt > maxVolt) { 
      IsInverted =true;
    }


   //Here I need to figure out how to work out percentage/litres/temperature C/F etc
  currentValue = ?


   Return currentValue
}

Open in new window




Can anyone help me with the calculation please, my brain isn't working today after a long weekend :)

although the example above is using %, I will never know if it is %, C, F, Litres etc
I will only know min and max VALUES, min and Max VOLTAGE and CURRENT VOLTAGE
websssCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
//assuming a linear relationship
currentVal = minVal+(maxVal-minVal)*(currentVolt-minVolt)/(maxVolt-minVolt)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
websssCEOAuthor Commented:
clever guy!
Thanks man
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.