You don't say what you want it to do if D7 is neither 3 or 5.
Assuming you want to display a blank (" ", in this formula), it's:
=IF(D7=3,SUM((+D8*180)+(+D9*30)),IF(D7=5,SUM((+D8*310)+(+D9*30)),""))
Replace the "" for 'whatever you want it to do if neither of the two conditions are met.