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: 
Basic advice: design as you go, and at each stage, use a print-out to tell you what values are entered.

```
cin >> n;

cout << "Please enter " << n << " values to sum: " << endl;

for(i=0;i<n;i++)
{
    cin >> arr[i];
    cout << "value #" << i << ": " << arr[i] << " entered." << endl;
}

```

You basically want to move on to the next stage of processing only when you're sure that your program works for entering the initial data. Take each stage of processing one at a time, and output what the current stage is. This makes it much easier to work out which stage of processing is causing an error. You can cut back on the print commands later on once it's working as intended, but I'd recommend leave then in there but commented out. Sometimes incorrect inputs cause errors again, and it's handy to re-enable the debug prints to tell you what's going on.
> 
> 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.