First things first:
int sparky[14];
will give you an 14-element array sparky[0..13]
, not 15 elements as you seem to think.
Secondly, your inner loop isn't quite right. Yours start at index 1 and go through to index 15 whereas, because C array are zero-based, you should be cycling from 0 through to 14.
You can fix that by changing the loop condition to while (counter < howmany)
and moving the counter++
to just before the end of the inner loop.
Just to clarify that point, you do actually start the loop at 0 but, because the first thing you do in the loop is counter++
before using sparky[counter]
, you're processing the elements starting at index 1. And, in the last run of the loop, where counter == howmany
(14 as per your other comments here), you increment it to 15 and use that, which is beyond the end of the array.
And, just to clarify that clarification :-), your loop is correct if you have howmany set to 14 (i.e., one less than the number of array elements) since, as you point out in a comment elsewhere, you load up element zero before entering the inner loop. I think you do still need to set high
whenever you set holder
though. If that's not done, I get two 6's and two 2's in my list and no 3 or 4.
As a side issue to your comment that howmany
is set to 14, I would suggest that variable names should echo their intent. You clearly have 15 elements in the array (indexes 0 through 14 inclusive). Don't take that as criticism, I'm just trying to help out.
Thirdly, (and finally, I think), you're not setting high
every time you're setting holder
- these should be kept in sync for your algorithm to work correctly.
Please let us know whether this is homework. If not, I'll post my solution. If so, you should work it out from the guidelines given in this, and other, answers. You should be aware that, if it is homework and you use a solution posted on a public forum on the internet (such as this one), you will almost certainly be failed for plagiarism. Do not make the mistake of thinking your educators don't check that sort of stuff.
Bottom line, while I'm happy to post my solution, you probably shouldn't use it as classwork. Top marks though for at least giving it a shot first. Most homework seeker seem to come here with nothing more than the specs :-)
Update: Since you posted the following:
Sorry to mention but this is part of an extra credit project for a class.
I guess it's classwork. So, no soup for you :-) Still, the three points above should be enough for you to fix it. If you have specific questions about them, feel free to ask in a comment attached to this answer.
Good luck.