sorting numbers

I cannot seem to get it sorting properly, if you run this you'll see the issue. It skips numbers.
How do I check to see the next highest number?
here is the exercise, I cannot figure it out without loading an array.
I am convinced I am missing something so simple...
Exercise 4. Write a C++/CLI program that creates an array with a random number of elements of type int. The array should have from 10 to 20 elements. Set the array elements to random values between 100 and 1000. Output the elements, fi ve to a line, in ascending sequence without sorting the array; for example, find the smallest element and output that, then the next smallest, and so on.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::setw;
using std::endl;
int main()
{
short* ii_numarray= 0;
short ii_rndnum = 0;
short* ii_placeholder = 0;
short ii_loop_counter = 0;
short ii_loop_counter2 = 0;
short ii_lowest = 0;
short ii_next_lowest = 0;
short ii_place_count = 0;
ii_rndnum = rand() % 10 + 10;

ii_numarray = new short[ii_rndnum];
ii_placeholder = new short[ii_rndnum];

for(ii_loop_counter = 0; ii_loop_counter <= ii_rndnum;ii_loop_counter++)
{
ii_numarray[ii_loop_counter] = rand() % 900 + 100;
}
ii_lowest = ii_numarray[0];
for(ii_loop_counter = 0; ii_loop_counter <= ii_rndnum;ii_loop_counter++)
{
for(ii_loop_counter2 = 0; ii_loop_counter2 <= ii_rndnum;ii_loop_counter2++)
{ //if it is less than the outter #, make it lowest
if(ii_numarray[ii_loop_counter] < ii_lowest)
{
ii_lowest = ii_numarray[ii_loop_counter];

}//endif
}//loop2
}//ext loop
cout << "the lowest is: " << ii_lowest << endl;
ii_placeholder[0] = ii_lowest;
ii_place_count = 1;

for(ii_loop_counter = 0; ii_loop_counter <= ii_rndnum;ii_loop_counter++)
{
for(ii_loop_counter2 = 0; ii_loop_counter2 <= ii_rndnum;ii_loop_counter2++)
{

if(ii_numarray[ii_loop_counter2] >= ii_lowest && ii_numarray[ii_loop_counter2] < ii_numarray[ii_loop_counter])
{
ii_next_lowest = ii_numarray[ii_loop_counter];
}


}

ii_placeholder[ii_place_count] = ii_next_lowest;
ii_lowest = ii_next_lowest;
ii_place_count ++;
}
cout << endl;

for(ii_loop_counter = 0; ii_loop_counter <= ii_rndnum;ii_loop_counter++)
{
cout << ii_numarray[ii_loop_counter] << endl;
}

cout << endl;
cout << endl;

for(ii_loop_counter = 0; ii_loop_counter <= ii_rndnum;ii_loop_counter++)
{
cout << ii_placeholder[ii_loop_counter] << endl;
}

return 0;
}
Topic archived. No new replies allowed.