Not able to see the mistake I have done while writing the code

Here is the code I have written for the question

#include
using namespace std;

int main()
{
int n;
cin >> n;
int a;
int sum =0;

for (int i=1;i<=n;i++)
{
cin >> a;
sum = sum + a;
}

while (sum >=0)
{
    cout << a << endl;
}

return 0;

}
After inputting the numbers I am not getting anything back,the compilation process ends.Please explain what I am doing wrong

@amarshmalik0 hey amar this question has not given you n of argument this is running stream and the first loop is run infinite time

Then How can I take the input for the integers a specified time without using the argument n?

Take while(true)
Inside that write your logic

I am not able to understand when to use while (true) please explain when to use it and how to set a specific condition to true

Also please explain whether the logic used is correct or not

@amarshmalik0 hey aman
Int n;
Int sum =0;
While( true ) {
Cin>>n;
Sum+=n;
If(sum>=0){
Cout<<n<<endl;
}
else{
Break;
}

@amarshmalik0 hey aman dry run your logic with given test case i think your loop will stop after taking 1 as input.