I am trying to make a program that asks for the size of an array, prompts the user to enter numbers into the array, and finally displays the numbers back to the user. When I use this code with more than 4 numbers I get this output
OUTPUT
Enter array size: 5
Enter number 1: 1
Enter number 2: 2
Enter number 3: 3
Enter number 4: 4
Enter number 5: 5
Number 1: 1
Number 2: 2
Number 3: 3
Number 4: 4
Number 5: -559823264
Program ended with exit code: 0
#include <iostream>
usingnamespace std;
int main(){
int arraysize, inputindex, arrayin, arrayout;
int array[arraysize];
//prompts user to enter size of the array
cout << "Enter array size: ";
cin >> arraysize;
cout << endl;
// user enters number in each slot of the array
for (inputindex=0; inputindex < arraysize; ++inputindex) {
cout << "Enter number " << inputindex+1 << ": ";
cin >> arrayin;
array[inputindex]=arrayin;
}
//displays numbers in array
for (arrayout=0; arrayout < arraysize; ++arrayout) {
cout << "Number " << arrayout+1 << ": "<< array[arrayout] << endl;
}
}