What's wrong with my code?

#include
using namespace std;
int main() {
int i;
int a[i];
int n;
cin>>n;
int sum=0;

	for(i=0;i<n;i++)
	cin>>a[i];
for(i=0;i<n;i++)
	{
		sum=sum+a[i];
			if(sum>=0)
			cout<<a[i]<<"\n";
		else 
		exit(0);
	}
return 0;

}
its my approach to the question of simple input .Getting test cases failed but running fine in my compiler.

hi @mehrasinghsumit,here you have made array a of size i where i is not initialized first so it is giving any random space to the array a,make the array a after taking the input n from user of size n and not of i.

its still not working

Instead of making an array what you can do is take a variable n and intitialize a variable sum as 0 then you apply a loop in which you will put a condition that is sum>=0 then take input of n inside the loop and caculate the sum by adding n and then check that if sum>=0 then print n. In your code you are taking input of n integers before in the array but you have to take an input of integer add that number to sum and you have to check that if sum>=0 then print that integer else dont print.

Hi Sumit,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.