I agree with Dan, Gan. Well mostly. I would replace the battery for sure especially if you know that it is several years old or more. As far as the charger goes most people would be better off replacing the charger as well. That being said most likely the cord has given in to the constant pulling and bending that is part of being a portable unit with a design flaw that could have been fixed years ago and saved a ton of resources for future generations. By making the cord replaceable by the end user. Another option would be to use a different cord than the single wire shielded cable that is used now. The shielding is what is used for the -return on this cable and where the cable enters the brick is where it fails most of the time. I have repaired a few of these in emergency situations and the actual fix is easy. However, just like Fort Knox, it's the getting in that proves to be the challenge. I have used knives, saws and even an eight pound sledge (Ok, I wore goggles and it was just for fun!) But the easiest method is a hot knife. It isn't neat and certainly not very professional but if the end result is a working charger that I didn't have to give eighty bucks of my Kids' education to a corporation that owns half of Fort Knox to replace (Bill Gates owns the other half) then I did OK. After repairing the cable I use the hot knife to melt the seam back together because it is quick. I use a cordless butane torch that came with soldering tips and a knife blade tip that screw into the soldering adapter that can be used without a tip as a mini hot air gun for heating shrink tubing. Refillable and portable fun!
If you replace the battery and the charger and still have problems it is possible that the magsafe board on the MacBook is bad. The battery connector board and cable can fail as well. And sometime the logic board will fail. These are usually the result of water damage that isn't obvious like that which occurs from sitting the computer on a ring of condensation left by a nice cold beer bottle. I hope your problem is just the battery and charger and you get a few more years out of your MacBook!