He bought 40/5=<<40/5=8>>8 boxes
He loses an average of 5-3.5=$<<5-3.5=1.50>>1.50 per box
So he loses an average of 1.5*8=$<<1.5*8=12>>12
#### 12