Not getting where iam going wrong .Passing only two testcases

#include
using namespace std;
int main() {
int n,sum=0;
cin>>n;
while(n!=EOF){
sum+=n;
if(sum<0)
break;
else
cout<<n;
cin>>n;
cout<<endl;
}
return 0;
}

@dbhavanishankar89 hey bhavni don’t do like this instead do this
#include< iostream >
using namespace std;
int main() {
int sum=0;
while(true)
{
int number;
cin>>number;
sum=sum+number;

  if(sum>=0)
  {
      cout<<number<<endl;
     
  }
  else{
      break;
  }

}
}

See if the first number let’s say is -21 and second number is 22.your logic fails.since initially -21+0 is less than zero…but actual inputs are -21+22=1>0 …so that’s what my doubt…help me

@dbhavanishankar89 hey Bhavani this question has some rule you have to print your value up to when your value is greater than or equal to zero. but that case you’re talking about has the first element having a negative value which means your first value will be negative and further value will not be processed.

i still have doubt.I want a call from you to clarify
Thank you

@dbhavanishankar89 hey bhavani make a call is not possible. Create a doubt we will assure you to resolve as soon as possible.

Can you tell me where my code failed?

@dbhavanishankar89 hey bhavani shankar let us consider this case
5
-2
-3
4
1
2
1
-1
-10
your output is
5
-2
-3
4
1
2
1
but it should be
5
-2
-3
4
1
2
1
-1