Count number of even and odd numbers from input I had to write a program that accepted five numbers from the user. Then it will display the number of odd and even numbers, and a total sum of all numbers.

#include &lt;iostream&gt;
using namespace std;

int main()
{
    int a;
    int b;
    int c;
    int d;
    int e;
    int sum;
    int remainder;
    int bremainder;
    int cremainder;
    int dremainder;
    int eremainder;
    int even;
    int odd;
    int total = 0;
    int Ototal = 0;

    cout &lt;&lt; "Please enter the 5 numbers you would like calculated: \n";
    cin &gt;&gt; a;
    cin &gt;&gt; b;
    cin &gt;&gt; c;
    cin &gt;&gt; d;
    cin &gt;&gt; e;

    remainder = a % 2;
    bremainder = b % 2;
    cremainder = c % 2;
    dremainder = d % 2;
    eremainder = e % 2;

    sum = (a + b + c + d + e);

    if (remainder = 0)
    {
        total+=remainder;
    }
    else {
        Ototal += remainder;
    }
    if (bremainder = 0)
    {
        total += bremainder;
    }
    else {
        Ototal += bremainder;
    }
    if (cremainder = 0)
    {
        total += cremainder;
    }
    else {
        Ototal += cremainder;
    }
    if (dremainder = 0)
    {
        total += dremainder;
    }
    else {
        Ototal += dremainder;
    }
    if (eremainder = 0)
    {
        total += eremainder;
    }
    else {
        Ototal += eremainder;
    }

    cout &lt;&lt; total &lt;&lt; "\n";

    cout &lt;&lt; Ototal &lt;&lt; "\n";

    cout &lt;&lt; sum &lt;&lt; "\n";
    system("PAUSE");
        return 0;
}
Do not use system("pause"). Read
this
Stop using using namespace std. Read
this
You have an unneccessary amount of variables. You don't need to have
a variable to hold the remainder for each number.
Just have a function that determines whether the input number is odd
or even. I think you might have to rethink the logic of your
program.




//Your function should do the following:
//MAX is a const int. In your case it is 5
    for(int i=0; i&lt;MAX; i++){
        if(numbers[i] % 2 == 0)
            evenNumbers++;
        else
            oddNumbers++;

        sum += numbers[i];
    }


Here is how I would have done it:

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;iterator&gt;

using std::cin;
using std::cout;
using std::endl;
using std::vector;



int main(){

    int value = 0;
    int oddNumbers(0), evenNumbers(0), sum(0);


    std::istream_iterator&lt;int&gt; begin(cin);
    std::istream_iterator&lt;int&gt; end;


    //while(cin &gt;&gt; value)
    //  numbers.push_back(value);

    //Instead of a while loop, I use input stream iterators.
    vector&lt;int&gt; numbers;
    std::back_insert_iterator&lt;std::vector&lt;int&gt;&gt; iter (numbers);

    std::copy(begin,end,iter);


    //Range based for-loop (C++11)
    for(auto i : numbers){
        if(i % 2 == 0){
            evenNumbers++;
        }else {
            oddNumbers++;
        }

        sum += i;

    }

    cout &lt;&lt; "# of odd numbers: " &lt;&lt; oddNumbers &lt;&lt; "\n";
    cout &lt;&lt; "# of even numbers: " &lt;&lt; evenNumbers &lt;&lt; "\n";
    cout &lt;&lt; "Sum of all numbers: " &lt;&lt; sum &lt;&lt; endl;



}