This is only to give an overview of the very long and complex story which Airbus to the production of the A330/A340:
The first task for Airbus was to produce the TA-11, a very-long-range aircraft with a smaller capacity than that of the 747 to allow more non-stop flights with more frequencies.
But the initial forecasts (around 1985) for the market was for only 200 aircraft, which was too few to make the project profitable. And the forecasts for aircraft targetting missions of medium-range routes was for about 600 units.
Producing the A330 alone wouldn't have been profitable as well, because there were some costly development to be made like the wings.
By producing two aircraft aiming at two different ranges of missions, later completed by derivatives such as the A330-200 or A340-300E, Airbus made economis of scale and proposed a better offer than one of the two aircraft alone.
There are other factors than the number of engines which make the A330 different from the A340: the MTOW is lower on the A330 because the aircraft aims at shorter operations.
The current project, as replacement for the A300/A310, is the A330-500.
Click for large version
Photo © Colin K. Work