Mercedes bought 22 cupcakes
Explanation
Let number of vanilla cupcakes=x
Number of chocolate cupcakes=y
When she eats 1 vanilla cupcake
Number of vanilla cupcakes remaining=x-1
Number of cupcakes remaining=x+y-1
Given
(1/7)(x+y-1)=x-1 (1)
When she eats two chocolate cupcakes instead
Number of chocolate cupcakes remaining=y-2
Given that
(1/5)(x+y-2)=x (2)
Consider equation(1)
(1/7)(x+y-1)=x-1
x+y-1=7x-7
7x-x-y=6
6x-y=6 (3)
Consider equation (2)
(1/5)(x+y-2)=x
x+y-2=5x
5x-x-y=-2
4x-y=-2 (4) solving (3)and (4)using
elimination method we get x=4
y=18
Total number of cupcakes Mercedes bought=x+y=4+18=22