This is a common phrase for expressing what must be done to get something that you want. Its good for casual and conversational situations. There are some famous phrases that use this structure:
You have to spend money to make money.
You have to give respect to get respect.
To make this phrase more formal, change "have to" to "must" and insert "in order to":
You must take three semesters of mathematics in order to graduate.