Doubt in the code of "simple input "

Please tell me what is mistake in my code . The test case 2 and 3 was not going correct .
the code is following:

#include
using namespace std;

int main() {
int n;
while(scanf("%d",&n)!=EOF)
{
int sum =0;
sum=sum+n;
if (sum>=0)
{cout <<n<<endl;}
else
break;
}

return 0;

}