I'm currently learning programming and learning C++. I'm trying to use the for each loop to print out an array but I'm getting some weird outputs. Here's my code.
#include<iostream>
using namespace std;
int main(){
        int length;
        cin >> length;
        cout << "Enter " << length << " numbers!\n";
        int x[length];  
        for (int i : x){
                cin >> i;
        }
        for (int i : x){
                cout << i << endl;
        }      
        return 0;
}
I ran a test and here's my input and output
5
Enter 5 numbers!
1
2
3
4
5
78344035
1
2031166200
32767
1528080880
If someone could tell me what I did wrong I'd really appreciate it. Thanks
 
     
    