Help me understand sorting please

Alright, so I want 5 int values from 0-9, which I will store in a vector. I need to iterate through all 5 integers to find all combinations that will equal a certain sum, lets say a const sum of 30. So, basically I need to find all combinations of numbers 0-9, totaling 30, in XXXXX format.

I've done a lot of googling and read up on next_permutation and sorting functions but I'm not sure how to go about doing this. Would anybody like to help me understand how I'd do this.

I could post my code so far, but I don't need answers, I need understanding. So any help and examples would be appreciated.

Thanks a lot!!!
Last edited on
Bump please?
It would really help if you were to clearly state your problem and pay attention to some of the answers given you instead of spamming.

http://www.cplusplus.com/forum/general/43881/

I have already shown you, very clearly, how to simply count through every five digit number and check to see if the digits add to 33. Incidentals about how the numbers are stored in your vectors are minor details that you should be able to figure out yourself.

I could post my code so far, but I don't need answers, I need understanding. So any help and examples would be appreciated.
Understanding starts with looking through what you have been given. What I have done so far is an elementary algorithm that you ought to understand if you want to get through things like next_permutation() and the like.

Why are you determined to do it the hard way?
Why do your questions and specifics keep changing?

The reason no one else has helped is likely because the help you have received so far is both elementary and sufficient. If I (or anyone else) has completely misunderstood something, that is something, but I'm not sure you even understand what you want. Do you want a combination or a permutation? Can the same digit appear more than once, as in "6 2 9 8 8"? Do you want them to add to 30 or 33?

Make up your mind, then be specific, and stick to one thread.
No one was responding to the last post.

The calculation doesn't matter, because I just want to know how to do it. So let's just say 30.

Each number can come up more than once as long as the combination equals 30.

I do not agree with you that you have given ample information for me to be able to understand what you did. I would hardly call your post on the other thread sufficient, otherwise I would not be asking this again.

I need a combination, but with each number being an element in a vector, not as a single integer.

Thanks a lot.
After less than an hour, then three, then two? On Memorial Day weekend? We want to help, but you need to be patient.

I'll continue in your other thread.
Topic archived. No new replies allowed.