So I am working on a problem for a program I am making...
Say I have two numbers: 10 and 100, than I have a variable. How would i find what percent the variable is between the two numbers?
So:
45 is 50% between 10 and 100
17.5 is 25% between 10 and 100
62.5 is 75% between 10 and 100.
But I need an equation that would work no matter what the 3 numbers were (assuming the number we are solving the percent of is between the two other numbers).
So what percent is 34 in relation to 20 and 300.
Or what percent is 79 in relation to 0 and 85.
I think I understand what you would like to work out, but I agree with rogerl that you examples may be wrong. I think what you've done (e.g. in your first example) is $(100-10)\times \frac{1}{2}=45$ and said therefore 45 is 50% between 10 and 100 which is isn't since $(100-10)\times\frac{1}{2}+10=55$ is.
To your question, how can we work this out generally. You may be able to see from what I did above but given some number $x$ in the range $a$ to $b$ we can work out what percentage of $x$ that is in between $a$ and $b$ with: $$ \text{Percentage}(x,a,b)=\frac{x-a}{b-a} $$
For one of your examples you have $x=34$ and $a=20$ and $b=300$ which gives: $$ \frac{34-20}{300-20}=\frac{1}{20} $$ which we can check by the more intuitive way of thinking about it, just remembering to add the $20$ which is where I think you may have went wrong: $$\frac{1}{20}\times (300-20)+20=34$$