Doubt in programming question - Simple Input

Hi, I do not know where in the code I am committing the error.
URL to Question - https://online.codingblocks.com/player/12975/content/4693

My current solution -
#include
using namespace std;
int main(){
//Declaration
int input_number_array[50];
int i =0;
int sum_of_numbers=0;

// logic, to check the number before addition. If it is, than break (loop break condition), Else continue
while(true)
{
cin>>input_number_array[i];
if(input_number_array[i]<0)
break;
else
{
cout<<input_number_array[i]<<endl;
sum_of_numbers+=input_number_array[i];
}

i++;

}

return 0;

}

Currently only one of the three test cases are passing. Please do let me know where I am wrong.

Hi, I have generated a pastee link of the code, it will be more confortable to read it.

URL is — https://paste.ee/p/fnsvP

Hey, can you please mention problem’s name also.

Hi! To find out what I can do, say @discobot display help.

you are checking if the input number is negative or not
but question requires to check if cummulative sum is negative or not
imput 1 2 88 -100 49… after input -100 the sum is 1+2+88-100 = -9 which is negative so it stop processing after -100

Hi … the question name is -“Simple Input” its the first question in challange 1.

Question Prompt is --“Given a list of numbers, stop processing input after cummulative sum of all the input becomes negative.”

Hey, as the problem says stop processing input after cumulative sum of all the input becomes negative, So there is no need to store the input in an array. Take a variable sum and write a while loop with condition while(sum>=0) take the input number and add it to the variable sum… by this whenever your cumulative sum will become smaller than 0 or negative loop will automatically break.

1 Like

Hi! To find out what I can do, say @discobot display help.

Hey, if you don’t have any further doubt on this problem then please mark this doubt as resolved.

explain in terms code???

For input
-5
500
-600

the output should be:
-5
500 ? Right?

1 Like

then why there is 49