X will be the amount of 1 dollar bill and y the 5 dollar bill
x1 + y5 = 40
x + y = 12
(I'm going to solve for x first, so multiply the bottom equation by negative 5)
x1 + y5=40
x-5+y-5= -60
(cross out the y and solve)
x-4 = -20
(divide)
x= 5
(place it in the equation you didn't use)
5 + y = 12
y = 7
he has 7 fives and 5 ones