# function to calculate total sale amount

I have a product that sells in a strange way.

The formula to get the current price is:

total_products_sold * 0.05

I need a function that will return the total sales value, given a total_products_sold value. This needs to figure out all past pricing, using the above formula.

e.g. if I sold 3 products, the total sales amount is:

1 * 0.5 + 2 * 0.5 + 3 * 0.5 = .30

I can't remember the formula, if its a factorial issue or a exponential type equation.

## Answers

Formula is

total(N) = 1 * 0.5 + 2 * 0.5 + ... + N * 0.5 = (1 + 2 + ... + N) * 0.5 = (check this link) ((N + 1) * N / 2) * 0.5

function could be something like

float total (int products) { return (products + 1) * products / 2 * 0.5; }