Answer:
#include <iostream>
using namespace std;
int main()
{
// Declare variables to store the number input by the user and the count of odd and even numbers
int number, oddCount = 0, evenCount = 0;
// Use a do-while loop to input numbers until the user enters a negative number
do
{
cout << "Enter a number: ";
cin >> number;
// Increment the count of odd numbers if the input number is odd
if (number % 2 == 1)
{
oddCount++;
}
// Increment the count of even numbers if the input number is even
else if (number % 2 == 0)
{
evenCount++;
}
}
while (number >= 0);
// Print the count of odd and even numbers
cout << "Odd numbers found: " << oddCount << endl;
cout << "Even numbers found: " << evenCount << endl;
return 0;
}
Step-by-step explanation:
This program will prompt the user to enter a number, and it will continue to input numbers until the user enters a negative number. For each number that is input, the program will increment the count of odd numbers if the number is odd, or the count of even numbers if the number is even. Finally, the program will print the count of odd and even numbers.
Here is an example of the output you would see if you ran this program:
Enter a number: 30
Enter a number: 17
Enter a number: 22
Enter a number: 9
Enter a number: 14
Enter a number: -5
Odd numbers found: 2
Even numbers found: 3