Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.