If I understand your problem is: you copied the code from a smart contract, and it allows you to execute the transaction, but when the user tries to withdraw the funds the contract returns the error.
Using the Solidity Visual Auditor ExtensionVisual Auditor Extension, you can see the provided code graphically.
See the image below of the code you provided!