Even/odd counter question

Write a program that accepts integers from the user and tells how many of the numbers entered were odd and how many were even. The program should stop asking for integers when the user inputs a zero.

- So I have most of the code working. I just cannot figure out what I am doing wrong when it comes to calculating how many odds or evens the user entered. Any help would be great for this noob coder!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main ()
{

    int n;
    int myCounter1, myCounter2;
    cout << "Odds and Evens\n\n" << endl;
    do
    {
    cout << "Please enter an integer: ";
    cin >> n;

    myCounter1 = 0;
    myCounter2 = 0;
    if (n%2 == 0)
    {
    myCounter1++;
    }
    else
    {
    myCounter2++;
    }

}
    while (n!=0);
    cout << "You entered " << myCounter1 << " even numbers, and " << myCounter2 << "odd numbers " << endl;

return 0;
}
closed account (48T7M4Gy)
lines 15 and 16 need careful attention, very careful attention :)
Ohhhh. I am bad. They should before the loop. Thanks!
Topic archived. No new replies allowed.