Sum up to an ammount (read!)

What if i have some integers (lets say 1 5 8 7 2 3 4 9 5 8 3 4 7 0) (uknown ammount or values of integers) and i want to use some of 'em to sum up to a number or close to it (closer = better) (lets say 20). When i say uknown values, i mean that the values would be inputted from a .txt file (random integer). How do i do that?

Comments

  • : What if i have some integers (lets say 1 5 8 7 2 3 4 9 5 8 3 4 7 0) (uknown ammount or values of integers) and i want to use some of 'em to sum up to a number or close to it (closer = better) (lets say 20). When i say uknown values, i mean that the values would be inputted from a .txt file (random integer). How do i do that?
    :
    Use a while-do loop to read them, and immediately add them to the sum.
  • I don't mean that. If i sum up all numbers, the total ammount will be higher that 20. Or i should while do loop while the total ammount is under 20 . hmm ok i got it thnx.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories