How to eleminate the -100

Do we know how many input we have to take or we just assume it 5?

Please share your question

hi @AVIRAL1101
you have to stop taking sum becomes less than 0.
No need to store any values in any array, Just take a variable sum to store the total sum, and another variable to take inputs. I am writing the algorithm below, hope it helps in clarifying the logic.

declare the variables, n, sum = 0.
take input for n,  cin >> n
add n to the sum, like sum = sum + n
while (sum >= 0) //do this till sum doesnt become negative
{ 
    //print the last value of n that was added to the sum and didnt make the same negative
    cout << n
    //keep taking user input for more values
    cin >> n
    // keep appending it to the sum to update it
    sum  = sum + n
}

@Ishitagambhir
I wanna know the question for this solution

@AVIRAL1101 https://hack.codingblocks.com/app/contests/1454/206/problem

@AVIRAL1101 you can try to submit on the hackerblocks link I provided above and see if it works :slight_smile:

yup it worked @Ishitagambhir

1 Like

@AVIRAL1101 i request you to delete your code from here now

already done :+1: @Ishitagambhir

1 Like

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.