Print the number of even and odd numbers

Hello I want my program to count the number of even and odd numbers inputed by the user, but it does not work. I want them to be able to input more than one integer. Thanks for your help. Example of output: There are 8 even numbers in the array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 int main()
{
	int integer;
	int odds = 0;
	int evens = 0;
	// integer and obtain integer. 
	while (true) {
		cout << "Please enter an integer\n";
		cin >> integer;
		if (integer == 0) break; // break outa here 
								 // determine if integer is even or odd 
		if (integer % 2 == 0)
			evens++;
		else
			odds++;
	} // end of while loop 
	cout << " Number of even numbers: " << evens << endl;
	cout << " Number of odd numbers: " << odds << endl;
	return 0;
} 
Last edited on
I would get the integer before the while loop.
Then move the one inside the loop to the end of the while loop.

Maybe change while (true) to while (integer != -1) or maybe zero.
I got it to work thank you for your help.
Topic archived. No new replies allowed.