Array and Loop trouble

Hola! I am having a little difficulty with this problem: using a loop print out the sum of five integers, provided by the user, greater than 0 and less than 15. My idea for the solution was an array that would hold the inserted values. Then a loop would change the n variable to do the sum. This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

int main()

{

	int integer[5] ;
	int sum ;

	cout << "Please insert five integers\n" ;

	cin >> integer[0] >> integer[1] >> integer[2] >> integer[3] >> integer[4] ;

	for (int n = 0; n < 6; n++)
	   {
		if ((integer[n] > 0) && (integer[n] < 15))
		{
		sum += integer[n] ;
		}
	   }

        cout << "The sum of all the numbers greater than zero " << "and less than 15 is " << sum << "\n" ;

        return 0;
}


I thought that integer[n] in the for loop would pull the correct number from the array as n increased and produce the correct sum, but as my presence here shows my assumption wasn't successful. My program ends up producing this:


Please insert five integers
1 2 3 4 5
The sum of all the numbers greater than zero and less than 15 is -1208219521


Any help on where my troubles lies?
Line 6: Initialize sum to zero.
*Smack forehead*

Thanks helios that solved everything.
Topic archived. No new replies allowed.