Print all the numbers before the cumulative sum become negative

i am not able to solve rhis probleml please tell me how to accept the integers .give me a hint for it

check out this code

#include<iostream>
using namespace std;

int main() {

	int n;
	int sum = 0;
	cin >> n;
	while (true)
	{
		sum = sum + n;
		if (sum >= 0)
		{
			cout << n << endl;
		}

		if (sum < 0)
		{
			return 0;
		}
		cin >> n;

	}
	return 0;
}

if you have any doubt in this code feel free to ask

can u please write this code using a for loop
]

am not getting whitle(true) condition

this means you have to always take input
there is no restriction on while loop it will always go inside loop, no condition
inside loop we will decide whether we have to further continue or not

can u please wirte this code in the for loop manner it will be very helpful

for loop may be more confusing in this situation
still here is code with for loop

#include<iostream>
using namespace std;

int main() {

	int n;
	int sum = 0;
	cin >> n;
	for(;;)
	{
		sum = sum + n;
		if (sum >= 0)
		{
			cout << n << endl;
		}

		if (sum < 0)
		{
			return 0;
		}
		cin >> n;

	}
	return 0;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.