This is a small program that is suppose to find out the sum of even numbers entered into an array.... but everything works fine without errors but the output am getting is a negative number.... -1717986920.
#include <iostream.h>
void main()
{
int sum=0;
int i, a[6];
int range;
cout<<"Enter a range"<<endl;
cin>>range;
cout<<"Enter some numbers"<<endl;
for(i=0;i<range; i++)
{
cin>>a[i];
}
if (a[i]%2==0)
{
sum=a[i];
sum=sum+a[i];
cout<<"Sum of even numbers="<<sum<<endl;
}
}