Positive and negative numbers

  • 3
  • Locked
Use the keyboard to enter three integers. Display the number of positive and negative numbers in the original set in the following form: "Number of negative numbers: a", "Number of positive numbers: b", where a and b are the relevant values. Examples: a) if you enter the numbers: 2 5 6 then we displ
You can't complete this task, because you're not signed in.
Comments (11)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Krig Raseri
Level 9 , Dallas, United States
5 August, 11:06
Used a similar setup to the other task like this one, and then just added a negative counter. It all worked perfectly and 0 didn't count for either, and yet it kept failing for some reason. Looked at the solution and it's pretty much the same. Oh well.
VikramSarath
Level 6 , Atlanta, United States
24 May, 15:44
The correct solution states
if (number1 > 0) {
            ...
        } else if (number1 < 0) {
            ...
        }
and I wrote the code as
if(a>0)
        {
          ...
        }
        else
        {
            ...
        }
The output was the same and it was correct, however the task status stated "task failed". the difference I see is the use of else if vs my way of using just else. I don't understand the difference... can any one shed some light on this.
Roman
Level 41
25 May, 05:54
Think about 0 (zero) :)
Ali_Alshehri
Level 5 , Saudi Arabia
24 April, 20:57
guys think about increment and decrement if the number > 0 then increment the positive counter if the number < 0 then increment the negative counter
IRFAN BAIG
Level 9 , India, India
2 March, 18:28
At last able to complete without loops.huff
Tomi
Level 6 , Warsaw, Poland
25 December 2021, 17:10
I have a good result (not counting zero as negative or positive) but I am still not able to pass condition "Note that "0" is not a positive or negative number".
whoseunassailable Backend Developer
4 January, 11:23
i am stuck at the same case. Can you please be willing enough to answer it?
Anonymous #10889854
Level 3 , Волгоград, Russian Federation
9 January, 21:03
Just use the > 0 and < 0 conditions to add to the counter variables' values.
Roman
Level 41
10 January, 07:43
Please post your question with the attached solution in the section Help.
Ali_Alshehri
Level 5 , Saudi Arabia
24 April, 20:58
just say number > 0 this mean not zero but positive
Ali_Alshehri
Level 5 , Saudi Arabia
24 April, 20:59
exactly!