I am beginner in C++ and was trying to insert data into an array through the for loop, however, it throws Stack around the variable 'numArray' was corrupted.
My code:
//Initializing and declairing variables
int numVal = 0;
int numArray[] = {0};
cout << "Enter the number of values to average: ";
cin >> numVal;
//Loop through to accept all values and allocate them to an array
for (int i = 0; i < numVal; i++) {
cout << "[" << i << "] = ";
cin >> numArray[i];
}
What's wrong with my code?
Edit: I must use array and not vectors.