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;
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;
}