There are many dangers to taking more pills than your doctor
has prescribed for you. The dangers depend on the type of pain medicine that you were prescribed. If you were prescribed a narcotic pain medicine such as hydrocodone oxycodone, then taking too many of these pills can make you sedated and more likely to fall or injury yourself. Plus, taking more of them will make any withdrawal symptoms you have worse or make you very constipated. Sometimes these pills are mixed with Tylenol (as is with Vicodin) and taking more than prescribed can cause you to overdose on the other drug.
One thing to keep in mind is that in the immediate post operative period, you should expect to be in some pain. The purpose of the pain medication is not to completely dull you from pain, but rather to make you as comfortable as possible without giving you unneeded side effects from the pain medicine.
I suggest that you schedule an appointment with your orthopedic surgeon
who performed the surgery
and (I assume) wrote you the prescription for the pain medicine. The two of you should discuss how much pain you are having and if that amount of pain is appropriate for your level of healing and the amount of pain medication you are taking. It is possible that you are just not responding to that type of pain medication and that you need a different prescription.