counting odd negative integers

for the life of me i cant figure out why my program wont count negative odd integers. Here is the code I am using:

int main () {
int odd = 0;
int number = 1;
int even = 0;
while (number !=0) {
cout << "Enter a Number : ";
cin << number;
cout << number;
cout << endl;
if ((number != 0) && ((number % 2) == 0)) {
even = (even + 1);
}
if ((number % 2) == 1) {
odd = (odd + 1);
}
}
cout << even;
cout << " even numbers";
cout << endl;
cout << odd;
cout << " odd numbers";
cout << endl;
Hint: When will number be equal to zero? Your loop will never stop.

1
2
3
4
5
6
7
8
9
10
11
12
while (number !=0) {
 cout << "Enter a Number : ";
 cin << number;
 cout << number;
 cout << endl;
 if ((number != 0) && ((number % 2) == 0)) {
  even = (even + 1);
 }
 if ((number % 2) == 1) {
  odd = (odd + 1);
 }
}
count odd negative

I see the program to count both odd and even numbers as long as they are not 0. Even and positive were not requested.
ok so the whole thing will look like this:

int main () {
int odd = 0;
int number = 1;
int even = 0;
int positive = 0;
int negative = 0;
while (number !=0) {
cout << "Enter a Number : ";
cin << number;
cout << number;
cout << endl;
if ((number != 0) && ((number % 2) == 0)) {
even = (even + 1);
}
if ((number % 2) == 1) {
odd = (odd + 1);
}
if (number < 0) {
negative = (negative + 1);
}
if (number > 0) {
positive = (positive + 1);
}
cout << even;
cout << " even numbers";
cout << endl;
cout << odd;
cout << " odd numbers";
cout << endl;
cout << negative;
cout << " negative numbers";
cout << endl;
cout << positive;
cout << " positive numbers";
cout << endl;
return 0;
}
Topic archived. No new replies allowed.