The ratio of the number of cakes Ann had to the number of cakes Beth had was 5:2, which is also 10x:4x.
After Ann sold 28 cakes, the ratio becomes 3x:4x
Therefore 28 cakes = 10x-3x = 7x
10x = 40
Ann had 40 cakes at first.
Hope this answers your question.