Guns and missiles are complimentary systems. Which is better depends on the target and circumstances.
Guns do best at short ranges, including point blank, and cannot reach as far as missiles. They also lose accuracy as range increases. The gun itself is very heavy vs. the damage a single round does, as is the mechanical stress (recoil) it puts on the hull when firing, limiting the size of ships that large guns can be placed on. But the per shot weight is low allowing large magazines without a significant design penalty.
Missiles have longer ranges, usually much longer, and accuracy is not effected by range. But most cannot be used against targets within a fairly long short range. Warheads are much heavier, as is the size, weight, and cost of the missile, so typically only a few are mounted on a vessel. But the launcher weight and firing stresses are much low, allowing even fairly small vessels (>50 tons) to mount several.
Simply put, a good warship design needs both.