Simple Input problem assignment 1

I know that in this code cin>>n won’t be there as End of file is already there. But, when it is there then why is it not outputting 1 but and rest is working fine?

#include
using namespace std;
int main() {
int n;
int sum=0;
cin>>n;
while(scanf("%d", &n)!=EOF && n<1000 && n > -1000)
{
sum=sum+n;
if(sum<0)
{
break;
}

   else
   cout<<n<<endl;

}



return 0;

}