Sum up to an ammount (read!) - Programmers Heaven

Howdy, Stranger!

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

Categories

Sum up to an ammount (read!)

SlladSllad Posts: 19Member
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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • SlladSllad Posts: 19Member
    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.