Random array

What I'm trying to do is have the 1 main loop that will print the numbers in ascending order checking the last number if it's bigger or smaller than the one before it. If the number is smaller it skips it.I'm just not sure if I have the condition loops/if statemen's correct.

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

//---------------------------------------------------------------------------

# include <iostream>
# include <conio.h>
# include <stdlib.h>
# include <ctime>
using namespace std;

void randomReplace(int[], int);
//---------------------------------------------------------------------------
int main()
{
const int SIZE = 10;
int array[SIZE];

srand( ( unsigned )time( 0 ) );

	cout << "array is ";
	for( int i = 0; i < SIZE; i++ )
	{
		array[ i ] = 1 + rand() % 100;    
		cout << array[ i ] << " ";        //prints random array in main()
	}
	cout << endl << endl;

	randomReplace( array, SIZE );

	system("PAUSE");//getch();
	return 0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void randomReplace( int numbers[], int SIZE )
{
	int smallest = numbers[ 0 ];
	int nextNumber;  
	int largest = numbers [ 0 ];

	cout << "testing";   

	for( int i = 0; i < SIZE; i++ )
	{

		 if ( numbers[ 9 ] < numbers[ i - 1 ] )// this is where I have trouble. 
		 {
			 for( int k = 0; k < SIZE; k++ )
			{
			nextNumber = numbers[ i ];
			numbers[0 + 1] = numbers[ i ];
			if( nextNumber == nextNumber )
			{
				cout << endl
					<< "next num is: " << nextNumber;
			}
		}
	

	}
cout << endl << endl << endl << endl
	  << "smallest is " << numbers[ 0 ]
	  << endl
	  << "largest  is " << numbers [ 9 ]
	  << endl << endl << endl
	  << numbers[0] << " " << numbers[1] << " " << numbers[2] << " "
	  << numbers[3] << " " << numbers[4] << " " << numbers[5] << " "
	  << numbers[6] << " " << numbers[7] << " " << numbers[8] << " "
	  << numbers[9] << " ";
}
If what you are trying to do is sorting in ascending order numbers from that array , you should use instead a priority_queue , or std::array or std::vector then sort it.
Your question is quite unclear to me. If you want to sort the array of random numbers yourself, try reading and learning about bubble sort or selection sort.
Topic archived. No new replies allowed.