CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2010
    Posts
    3

    help on algorithm

    Hi,

    I need some help with an algorithm that can do the following.

    The method receives 3 input parameters:

    1. double sum;
    2. double[] shares;
    3. int decimals;

    Return: double[] values;

    For instance if:
    sum = 200;
    shares = {30.0, 20.0, 50}
    decimals = 2;

    return: {60.00, 40.00, 100.00};

    Point is, the sum of the elements should equal to the input parameter sum.

    If the shares array does not sum up to 100% it should calculate the relative sum and use this instead.

    Example:
    sum = 200;
    shares = {30.0, 20.0} //sum is 50... recalculate to get {60,40}
    decimals = 2;

    return: {120.00, 80.00};


    Any help is really appreciated!

  2. #2
    Join Date
    Sep 2009
    Posts
    3

    Re: help on algorithm

    Don't you just multiply every element in shares[] by sum/(sum of shares[])?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured