Good morning everybody. I have tried to fill an array with elements enterd by the user; the problem is that while I have already found an answer to this on the internet, it says that my code should work, but it doesn't. Specifically, the computer says that the program stopped working after I try to run it, and honestly I don't really understand where I made a mistake. The code is the following:
#include <iostream>
using namespace std;
void getarray (int[],int);
void print (int[],int);
int main(){
const int size=10;
int n[]={0};
getarray (n,size);
print (n,size);
}
void getarray (int n[],const int size){
cout<<"Insert elements to fill the array:\n";
for (int i=0;i<size;i++){
cin>>n[i];
}
cout<<"Filling completed.\n";
}
void print (int n[],const int size){
cout<<"The inserted array is:\n";
for (int k=0; k<size; k++)
cout<<n[k]<<" ";
}
Used simply to get the array and print it.