#include
using namespace std;
int main() {
int x;
cin>>x;
int y=x;
while(x+y>=0){
cout<<x<<endl;
cin>>x;
}
return 0;
}
Why is my test case 1 and test case 2 not working succesfully despite the fact that they r workin perfectly on sublime text.please help me
your approach is wrong
try for this input
100 -50 -50 -10 -10 -1000
why you are adding x and y
your y is first value only
read question again
you have to Print all the numbers before the cumulative sum become negative.
correct approach
#include <iostream>
using namespace std;
int main() {
int x;
cin>>x;
int sum=x;
while(sum>0){
cout<<x<<" ";
cin>>x;
sum+=x;
}
return 0;
}
if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved 