If you have a range $[A,B]$ and want to linearly transform it to the range $[C,D]$, which is the simplest option, and I assume the one you are looking for, then the correct function is $f(x)=C\left(1-\frac{x-A}{B-A}\right)+D\left(\frac{x-A}{B-A}\right).$ For example, we have that $f(A)=C\cdot 1+ D\cdot0=C$, and $f(B)=C\cdot 0+D\cdot1=D$, so that the minimum of the first range gets sent to the minimum of the second range, and similarly with the maximums. Notice that as $x$ increases from $A$ to $B$, the quantity $\frac{x-A}{B-A}$ changes linearly from 0 to 1. However, there are infinitely many other, non-linear functions sending the range $[A,B]$ to the range $[C,D]$, and which one is best suited to your needs may depend on the meaning of the data you are working with.
So, to linearly scale $[40,100]$ to $[0,100]$, the function works out to $f(x)=\frac{5}{3}(x-40),$ and to linearly scale $[8,35]$ to $[0,100]$, the function works out to $f(x)=\frac{100}{27}(x-8).$