What factor or factors led to the defeat of Carthage in the Second Punic War?

The Second Punic War began with the Carthaginian commander Hannibal invading Roman Italy after sacking a Spanish town under Roman protection. Hannibal defeated 3 Roman armies and ranged freely over much of southern Italy for 15 years, but was defeated at Zama in North Africa in 202, leading to the surrender of Carthage. What went wrong for Carthage?

placeholder text for bug in Chrome