This happens when I start with a positive integer.
2/3/2020 8:19:03 PM
Why you assigning n to sum?
If you your summing only negative numbers..
First cin for n, has no use anywhere..
You must enter 0, to terminate while loop at end..
I originally had int sum = 0; however it was still giving me +1 to the answer.
-1 -2 -3 1 2 3 0 returns -5 when int sum = 0;
the very first one? how is it initialized then?
Remove the 1st cin, then initialize n other than 0.
Or else use do while like
how do i keep values greater than 0 from being input into n though?
cause even with the do while it inputs all numbers instead of just the negatives
cin >> n;
if (n < 0);
sum += n;
while (n != 0);
Cout << “Sum of negatives: “ << sum << endl;
it inputs every number even if its not < 0??
No. I only calculates negatives... Can you update your code by what you are trying?
And after if(n<0); error, remove ;. there should be no semi colon,..
-1 is taken into n.
Remaing -2 + -3 = -5
So remove first outside cin>>n ;
GET THE FREE APP
Learn Playing. Play Learning
Send us a message