How to solve this?

i am unable to so print the number before the cumulative sum becomes negative.

#include<iostream>
using namespace std;
int main()
{

    int cumSum=0;
    while(true){
        int data;cin>>data;
        cumSum+=data;
        if(cumSum>=0)cout<<data;
        else break;
    }
	return 0;
}

we are taking input and add it to cumSum
now check if cumSum is positive
if yes we print it
otherwise we break and come out of loop

while(true) means there is no restriction while entering into loop it always allow you to enter inside loop

Modified Code

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning: