Problem:

Calculating the credit that remains after each purchase is made.
Once the credit limit (stored in cell B1) is exceeded, zero is to be returned for all further purchases.

Solution:

Use the MAX and SUM functions in the following formula:
=MAX(0,$B$1-SUM($A$4:A4))