Results 1 to 7 of 7

Thread: A programming question maybe!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Your very own Pikachu! Banned Peegee's Avatar
    Join Date
    Mar 2001
    Posts
    19,488
    Blog Entries
    81

    Grin A programming question maybe!

    Or excel works too, but you would have to hand hold me with excel.

    Pretend for argument's sake I'm an idiot who only can program in C

    good luck!

    In today's episode, PG receives a call from a client. The client was debited $5,278.53 (eg) out of their bank account and does not know what payments break down this total.

    The good thing is that I or the client can pull up a list of transactions that went out on that day.

    eg:
    2859.34
    128.33
    483.44
    592.22
    1820.00
    500.00
    719.19
    1400.00
    300.00

    (so the transactions that add up to the figure needed are: 2859.34, 300, 1400, 719.19)

    How would I go about programming this? This is how I would start -

    1) go down the list and grab the line as a variable
    2) is the variable > the figure sought y ? if yes skip
    3) now i have variable x which is < y
    4) go down the list. is x2 > y-x1 ? if yes skip
    5) if no, is x2 = y-x1? if yes finish return x1 and x2 (how?)
    6) if no, store x1 and x2 somewhere. x1 = x1+x2
    continue

    but this only checks whether 2 numbers add up to y. Since there could be potentially infinite numbers, I am open to using an array that does not have a set amount of variables (but something like 50 would be fine lol I am not going to read out that many numbers to a client when i could be charging them 100s of dollars in service fees by saying 'nope.avi' )

    Does this make sense? I feel like people who haven't quit programming for 13 years (sorry) are having an aneurysm reading this.

    edit: lol yes there can be more than one solution. is this question too complicated to solve?

    I found this online - read this for more discussion - http://www.mrexcel.com/pc09.shtml
    Last edited by Peegee; 02-09-2012 at 10:20 PM.

Posting Permissions

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