Hey all,
I'm fairly new to C++ and am trying to write a program that continues asking the user for a number until "0" is entered. I am supposed to count the number of positive, negative, odd, and even numbers that the user has entered once the program is terminated(0 is entered by the user). I'm having trouble with the counting portion as all I get is zero each time for all the counts. Also, I am not supposed to count the "0" that is entered when the user wants to terminate the program. Can anyone kindly point me in the right direction?? Thank you....
#include <iostream>
using namespace std;
int main()
{
int number = 1,odd = 0,positive = 0,negative = 0;
while (number != 0)
{
cout << "Please enter a number (0 to exit): ";
cin >> number;
}
if ((number%2 == 0) && (number != 0))
{
number++;
}
else if (number%2 != 0)
{
odd++;
}
else if ((number > 0) && (number != 0))
{
positive++;
}
else if ((number < 0) && (number != 0))
{
negative++;
}
cout << number << " even numbers" << endl;
cout << odd << " odd numbers" << endl;
cout << positive << " positive numbers" << endl;
cout << negative << " negative numbers" << endl;
}