That is not your only problem. C++ does not allow a VLA, (Variable Length Array). The size of the array must be known at compile time. This can be with a constant number like "20" or a variable defined as a constant.
With what yo started with:
1 2
int n;
int arr[n];
"n" is defined and storage space is reserved, but the variable is uninitialized and you have no idea what that garbage value is. Then you try to make an array with some unknown value. Along with C++ not allowing VLSs a (0) zero length array or a negative number is not allowed. It must be a positive number greater than zero.
Now if you want to get a value for "n" and create a dynamic array that will work.
To be fair some compilers still allow VLAs, but do not count on that being the norm.
Next is the 2 "cin" statements. Each needs a prompt so the user will know what to enter. Or you will need to provide a printed copy of the source code, which not every user will know how to read, or printed instructions to tell the user what to enter and when.
1. declare the array larger than the size the user is going to input:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main()
{
// create a larger than expected array on the stack
int arr[100];
std::cout << "How many ints to store? ";
int arr_size;
std::cin >> arr_size;
std::cout << "You can store " << arr_size << " items.\n";
}
2. get the needed size from the user and create the array to be on the heap using new[]:
#include <iostream>
int main()
{
std::cout << "How many ints to store? ";
int arr_size;
std::cin >> arr_size;
std::cout << '\n';
std::cout << "You can store " << arr_size << " items.\n";
// create the array on the heap to the required size
// it requires using a pointer
int* arr = newint[arr_size];
for (int i { }; i < arr_size; ++i)
{
std::cin >> arr[i];
}
std::cout << '\n';
// with each new/new[] you have to delete/delete[]
delete[] arr;
}