+ 2

Do...while loop help

Question is: User enter a positive number and syntax execute “Enter a number: “ User enter a negative number it stop and will say “STOP! You entered a negative number” It should also count the number of positive number entered It should also sum the number of positive number enter.

3rd Feb 2018, 7:04 PM
1000 Scrubs / Mins.
1000 Scrubs / Mins. - avatar
10 Answers
+ 18
@Limitless , i think u should take input in an array & then process ... it would not be possible here to give input 1 after amother after seeing the output
4th Feb 2018, 4:48 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 16
@Limitless , in that case it will throw exception if u'll enter only non -ve numbers
4th Feb 2018, 8:43 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 14
@Limitless //try entering 1 2 , ... since 2>=0, the do while () loop'll run again & will not found any user input //for n positive elements , loop will run n+1 times and there are only n numbers as input
4th Feb 2018, 9:33 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
But yes, Ravi has a point. You should at least try the code first, and only when you fail it, you should ask the community. That way we can help you
3rd Feb 2018, 7:56 PM
Limitless
Limitless - avatar
+ 3
did you try to write the code and failed? if so please post the code, I will help you
3rd Feb 2018, 7:23 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
3rd Feb 2018, 7:53 PM
Limitless
Limitless - avatar
+ 3
different inputs should be given on different lines: Input box: 5 {enter} 6 {enter} 7 {enter} -8 Using an array in my opinion will take up more memory, unless the question specified that we should use an array.
4th Feb 2018, 8:35 AM
Limitless
Limitless - avatar
+ 1
hmm I didn't get any Exceptions
4th Feb 2018, 9:16 AM
Limitless
Limitless - avatar
+ 1
ohh, so you mean that when there's no further input the loop also stops. ok edited code again
4th Feb 2018, 10:09 AM
Limitless
Limitless - avatar
4th Feb 2018, 8:48 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar