Why does it cost to make an iphone app?

I just don't understand why it would cost you to make an app? I do understand the 100 dollar fee apple charges you to publish it to itunes, but i don't understand why it would cost thousands of dollars if your creating the coding off by scratch? If you are creating the codes why does that cost thousands of dollars? It should be free since you are manually typing in the codes? It might be a dumb question but i really just do not understand it?

First: Legal reasons - if you pay money then you are legally liable for damages that could go against the money, even with the complex contracts Apple has you sign.
Second: Commitment- If you pay 100 per year then your more likely to be committed to making Apps for the Apple App Store so that you can at least earn a gain of 100 for that year you were developing apps for Apple.
Third: Less chance of sabotage - If you create an app to gain access to or sabotage persons, data, hardware, etc. Then the odds of you creating an app to do something like that are dramatically decreased because you have paid somebody 100 and they also have your information. (not like you couldn't apply with fake information)

Their are reasons, although I do believe apple might potentially have a better app store if they opened developers licenses to the public. Then again, I wouldn't want an uneducated person creating an app that would damage my phone in some form.