Autozone or Advance Auto usually put batteries in for free. Batteries can fail fo many reasons. What usually happens if the cables are not corroded (which is a major source of battery / charging issues) is the battery has sat under full charge for a while (many times from not being used, or just normal day to day using the radio with the car off or lights being left on, etc.) and the battery deteriorates and eventually fails prematurely. A fully charged battery is ~12.6 volts, but if a battery is 12.1 volts you will probably not notice it, but that is considered 50% discharged. A battery that sits under 90% discharged for a period of time can begin the sulfation process and by the time you notice it, it is too late. Many times the car will start when left overnight or when you go out to lunch, but on the return trip the car won't start. This is because the battery will generate a charge when left unused overnight or for a few hours, but when trying to restart immediately after turning off, the battery is too weak. Leaving the car sit overnight and the process is restarted - car starts in the morning.
The bottom line is to always make sure the terminals are clean and tight and have the battery occasionally checked to see if it is below full strength. If it is, charging the battery up to full charge is the best way to guarantee a battery that last a long time. It can be inconvenient to do this, but like most things, extra care pays dividends. Advance and Autozone charge batteries for free, too. I would hit them up for a battery. Good luck.