Help with arrays

Hi guys, I'm writing my first intro programming midterm tomorrow, and need a little help with arrays. This is my first time programming so I'm very new.

I want to create a program that stores 10 numbers (from input) into an array, and display the sum of those numbers. However, when I compile the code that I make, no matter what my input values are, I always end up with the answer 5373728.

Is there any specific reason for this? From what I can tell the code looks good, mabye its just a problem with my compiler? Any help before my midterm would be much appreciated. Thanks :)

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

int main(){
int sum, a[10];
int i = 1;


for (i; i>=10; i++)
{
cin >> a[i];

}

sum += a[i];
cin >> sum;
return (0);

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cmath>//you don't need this in this case.
using namespace std;

int main()
{
    int sum=0, a[10];
    int i = 0;
    for (i; i<10; i++)
    {
        cin >> a[i];
    }
    for(i=0;i<10;i++)
    sum += a[i];
    cout<< sum<<endl;
    return (0);
}
Topic archived. No new replies allowed.