Question: I have this code and its job is to ask the user if how many elements they would like to enter in the array - the user then enters their desired elements - *the elements are integers* -then the program solves for the sum of the entered numbers.

Here's the code:

```
#include <iostream>
using namespace std;

int main()
{
int arr[20], i, n, sum=0;

cout<<"How many elements you want to enter?: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";

for(i=0;i<n;i++)
cout<<"How many elements you want to enter?: ";
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
for(i=0;i<n;i++)
{
cin>>arr[i];
}

cout<<"Sum of all Elements are: ";

for(i=0;i<n;i++)
{
sum=sum+arr[i];
}
for(i=0;i<n;i++)
{
   cout<<sum;
   getch();
}

```

I doesn't seem to work and the program doesn't run, so I can't put the actual output.

Expected output would be the sum of all the elements (integers) that the user entered.

Answer: 
Does it have to be an array? you can do it in a simpler way like this: 

```
cout << "Enter number of elements\n"; 
cin >> n 

cout << "Please enter the elements \n"
int temp = 0; 
int sum = 0;
for(int i = 0; i<n ; i++){

   cin >> temp; 
   sum+=temp;
} 

cout << "Sum is: " << sum << endl; 

```

One thin you need to note, you did not restrict the user to the max array size .. say he/she said 21 then you'll have an overflow which produces error. 

Since you're using C++, I would suggest you go with vectors, or use the simple way I stated above.
It is helpful to show the output or error message. 

Try to convert cin into an integer or float for:

```
cin>>arr[i];

```