There is no exact science for cost estimation — estimates are wrong by construction. The best you can do is improve confidence with historical data, decomposition, and empirical models.
Key facts
Estimates are guesses; calibrate with past projects.
Decompose: small parts are easier to estimate than the whole.
Defer estimation if you can — accuracy ⇧ as the project progresses.
There is no exact science for cost estimation - it will never be considered as all accurate.
No person can reasonably predict what can go wrong in the project.
Most estimation methods assume things will proceed as expected and simply adds some slack to account for what can go wrong.
Possible solutions
Delay estimation - 100% accuracy but less usefull
Base estimation on data from previous projects that have been completed.
Break the system to smaller parts and generate the estimates for smaller parts, which is easier.