bubble sort breaks after 5?

For some reason, when I enter anything above 5 to be sorted, it breaks? Works completely fine if I enter 5 or under.

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
  #include<iostream>
using namespace std;

int main(){
    
    int temp, count;
    int array[count];
    
    cout << "How many numbers do you want to sort? ";
    cin >> count;
    
    for(int i = 0; i < count; i++){
        cout << "[" << i+1 << "]" << " Enter a number: ";
        cin >> array[i];        
    } cout << endl; 
    
    cout << "Your Input: ";
    for(int j=0; j < count; j++){
        cout << array[j] << " ";         
    } cout << endl;
    
    
    for(int i2 = 0; i2 <= count-1; i2++){
        for(int j = 0; j < count-1; j++){
            if(array[j] > array[j+1]){
                temp = array[j];
                array[j] = array[j+1];
                array[j+1] = temp;        
            }        
        }         
   } cout << "Sorted Output: ";
     
     
    for(int i3 = 0; i3 < 5; i3++){
        cout << array[i3] << " ";  
    } return 0;
}



Output over 5: This example only took 6 inputs and didnt display or sort properly?
1
2
3
4
5
6
7
8
9
10
11
12
How many numbers do you want to sort? 7
[1] Enter a number: 1
[2] Enter a number: 3
[3] Enter a number: 5
[4] Enter a number: 7
[5] Enter a number: 4
[6] Enter a number: 2

Your Input: 1 3 
Sorted Output: 1 3 5 7 4 

Process exited with code: 0


Thank you
1
2
3
 for(int i3 = 0; i3 < 5; i3++){
        cout << array[i3] << " ";  
    }


This only prints out 5 elements
Topic archived. No new replies allowed.