let the cost of 3 bags of chocolate be x and that of gummy be y. Thus to solve the question we form systems of equation as:
3x+7y=22...............i
x+3y=8.....ii
from ii
x=8-3y........iii
substituting iii in i we get:
3(8-3y)+7y=22
24-9y+7y=22
-2y=-2
y=1
thus the value of x=8-3*1=5
thus the price of each bag of chocolate is $5 and that of gummy is $1