If the user input is a value in centimer, you'd have to find out which one is the biggest, for example, if he enters 20cm of width and 5cm of height :

width = maxwidth
height = 5/20 * maxheight

Then your rectangle should be the right ratio and will never go beyond the maxwidth or maxheight (note that some specific rectangle like squares might be a problem).

Related Query