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.


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;

Need Your Help

iPad popover from uitableview, use a disclosure indicator or no?

ipad uitableview uipopovercontroller uipopover

Asking for your opinions and best practices here about the use (or not) of a disclosure indicator arrow within a UITableView cell where selecting that tableview cell will launch a popover to choose...

C++/CLI Settings.settings designer like in C#

c# c++-cli settings application-settings

I am currently writing my GUI program in C++/CLI. (I know, not good. And I am not sure about it ever since I first thought about switching to C#. Another Question of mine).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.