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.
> 
> Here is the program for your problem description.It takes input from the user to how much elements you want to enter into the array then it take elements and saved in an array then calculates the sum of array elements.
> 
> 
> 

```
#include<iostream>
#include<conio.h>
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++)
   {
   cin>>arr[i];
   }
   cout<<"Sum of all Elements are: " << endl;

   for(i=0;i<n;i++)
   {
    sum=sum+arr[i];
    cout << "sum of a[" << i << "] = " << sum << endl;
   }
  cout<< "the sum of all the elements (integers) that the user entered = " << sum;
  getch();
  return 0;
  }

```

Now this program gives the information sum of a[i] elements is and so on to the end of the loop.