First let's define the variable we need to solve:
C = Number of cartons of milk to start
Then let's put the amount of cartons sold in the morning and the afternoon in therms of C:
M = Number of cartons sold in the morning = 2/5(C) = 0.4C
A = Number of cartons sold in the afternoon = 3/4(1-2/5)(C) = .75(.6)C = .45C
Finally, create an equation for how the number of cartons sold in the morning relate to the number of cartons sold in the afternoon:
M + 24 = A
Now insert the terms for M and A as they relate to C and solve:
0.4C + 24 = 0.45C
0.05C = 24
C = 480 cartons