Why does eating excess carbohydrates or proteins cause you to gain fat?

Please explain some of your ideas on this question so that we can critique your thinking.