counting positive and negative numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • masqwerty16
    New Member
    • May 2015
    • 8

    counting positive and negative numbers

    i don't know the codes to count how many negative and positive.. can you help me with the codes to count negative and the positive numbers? here is my code i can't finish it yet 'cause i don't know the codes or the condition.. hehehe.. :D


    Code:
    #include <iostream.h>
    
    main ()
    
    	{
    		int x;
    		int count[100];
    
    		cout << "Input 10 numbers: ";
    		for (x=0; x<10; x++)
    		cin >> count[x];
    	}
    Last edited by zmbd; Nov 15 '15, 02:52 AM. Reason: [z{please format script using the [CODE/] tool}]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Just write a loop that goes from 0 to 99. Inside the loop check each element of the array to be positive using an "if" statement:

    Code:
    if (count[x] < 0)
    {
       add to the negative total
    }
    else
    {
     add to the positive total
    }
    I'm not supposed to write the whole code for you.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      By the way, what do you want to do for a value of zero, which is neither positive nor negative. I'm not suggesting there is a right or wrong answer to that question -- but you need to decide before you can write the code.

      Comment

      Working...