For this case we are going to define the following variables:
x: number of cups of sugar
y: number if apples
We then have the following relationship:

For 4 apples we have:

From here, we clear the value of x.
We have then:
Answer: you need 1/2 cups of sugar if you have 4 apples