If the ratio is 4:5, then we have 4 + 5 = 9 "parts" of the ratio. What we want to do is to divide 18 by 9 to find out how many cups are in such a "part":
18 / 9 = 2
So if we know that there are 2 cups in each "part", If we want to make the ratio 4:5, all we need to do is to multiply 4 by 2 and 5 by 2:
4 * 2 = 8
5 * 2 = 10
So from 18 cups we can make two groups of 8 and 10 cups to keep the ratio of 4:5.