One thing I'll add to this is the number one reason given for why there were never any more moon landings, is because it was too expensive. Meaning they really weren't all that important. And they most likely never would have happened if the US wasn't competing with the USSR for bragging rights.
Well to a large extent you are correct about the cost of the missions not being immediately justifiable in light of the economic woes of the 1970s, however, I will say that the reasons for undertaking the mission were not purely pride, but rather were based on strategic national policy. The US hoped to benefit, and in most cases, did benefit, from the missions, in the following respects:
- Development of advanced rocketry technology, including improvements in propulsion, guidance systems, computer control, and communications, all of which have military applicability. It was expected that much of this would be applicable to ICBMs, but as it happened, as time progressed we wound up transitioning from liquid fueled engines to solid fuel motors for ICBM propulsion, nonetheless, the advances in guidance systems and heat shields for the re-entry vehicle would have been of great benefit. Indeed, it was military applications going back to the A4/V2 theater rocket that enabled civillian space flight (and it was a V2 launched in a suborbital trajectory as a propaganda exercise and scientific experiment by the Third Reich that became the first manmade object to enter outer space).
- Prior to the 1967 Outer Space Treaty, the opportunity existed to potentially exploit the moon as a launch site for nuclear weapons, and after 1967, a certain imperative existed to be able to verify that the Soviets were disinclined to attempt such exploitation (the treaty itself only happened because by 1967 the US was so far ahead of the Soviets when it came to the race to land on the moon that the Soviets already would have looked at it as a probable lost cause, and would have viewed the Outer Space Treaty as crucial to precluding American militarization of the moon,
- The advances in space-to-ground communications, orbital rendezvous and extra vehicular activity made during the Gemini and Apollo missions would prove invaluable for the deployment, repair and recovery of military spy satellites (and also had the scientific benefit of enabling the deployment, recovery and repair of the Hubbard Space Telescope, which initially launched with a defective lens, which had to be replaced in orbit, and which required additional servicing which the Shuttle completed in her final flights).
- Other advances in military and civillian technology including computer systems, food processing, power sources such as fuel cells, solar panels and Radioisotope Thermoelectric Generators , and indeed even the memory foam pillows that I use when sleeping to support my arthritic net were expected and obtained as a result of the NASA Space Program in the 1960s.
- Lastly, the expenditure on the Space Program provided an enormous economic stimulus, which helped secure the 1960 exit of the US from the unpleasant and now largely forgotten 1957-1959 recession, and which helped to provide some stabilization to the turbulent economy of the 1960s. Of course this combined with increased federal debt and a transition to reliance on monetary policy enabled by the Nixon Shock, which decoupled the US dollar from gold and silver backing (remember how there used to be Treasury Notes for each denomination, convertible to gold, and Silver Certificates, convertible to silver, in addition to Federal Reserve Notes?) combined with the OPEC oil embargo led to the runaway inflation of the 1970s, but that inflation was inevitable, and on the whole the US entered the 1980s in much better economic health than, for example, the UK, which in that era regarded having a space program as a waste of money (fortunately this is no longer the case).