Given a list of numbers, stop processing input after cummulative sum of all the input becomes negative?
solution
After using cs>=0 its giving wrong answer…as it works till cs doesnot become negative…how to stop when there is no input but cs>=0?
#include
using namespace std;
int main()
{
int n;
cin>>n;
int cs;
cs=n;
if(n>=0)
cout<<n<<endl;
while(cs>=0)
{
int t;
cin>>t;
cs=cs+t;
if(cs>=0)
cout<<t<<endl;
}
return 0;
}