By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

counting positive and negative numbers

P: 8
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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  3. main ()
  5.     {
  6.         int x;
  7.         int count[100];
  9.         cout << "Input 10 numbers: ";
  10.         for (x=0; x<10; x++)
  11.         cin >> count[x];
  12.     }
Nov 13 '15 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 9,197
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:

Expand|Select|Wrap|Line Numbers
  1. if (count[x] < 0)
  2. {
  3.    add to the negative total
  4. }
  5. else
  6. {
  7.  add to the positive total
  8. }
I'm not supposed to write the whole code for you.
Nov 13 '15 #2

Expert 100+
P: 2,398
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.
Nov 13 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.