|
|
Please enter your numbers. 4 |
while( n < 3 ) { ... }
.do { ... } while( num < 0 );
.)n == 3
, but you won't need that after you change the while loop's condition.Please enter your numbers. 3 |
Please enter your numbers. -2 -2-4 -6-8 -10-12 -14Error - you entered three negative numbers. -14 -16-18 -20-22 -24-26 -28-30 -32-34 -36-38 -40-42 -44-46 etc. |
(n < 3)
and it will exit the loop after one negative number is entered, instead of after the third, which is why I decided to change it to (n == 3)
. I could be wrong, but I just need it to exit after the third neg. number is entered not after the first.
|
|
v245-2% ./a.out Please enter your numbers. 2 2 3 5 6 11 -3 shouldn't exit the loop here - only on the third 8 shouldn't display sum unless it is positive or 3rd neg v245-2% |
|
|
|
|
How did you know to tuck the if statement inside the loop? Why did you decide to start off dealing with the counter part of the problem first? In other words, I had trouble deciding what to deal with first, the number being less than zero or the counter. |