wrong answer due to output

#include
using namespace std;
int main()
{
int a[5],i;
for(i=0;i<5;i++)
{
cin>>a[i];
}
cout<<endl;
for(i=0;i<5;i++)
{
if(a[i]==42)
break;
cout<<a[i]<<endl;
}
}
pls help!!