Hello everybody, really need some help getting this code to add up even and odd numbers from a set of integers. But it also needs to default or continue through if input is incorrect (i.e.- $,@,#,3.4) and so on. Here is what I have so far. Thank you.
#include <iostream>
#include <iomanip>
using namespace std;
const int N = 20;
int main()
{
//Declare Variables
int counter;
int number;
int zeros;
int odds = 0;
int sumOdds = 0;
int evens = 0;
int sumEvens = 0;
cout << "Please enter " << N << " integers, Positive or Negative " << endl;
cout << "The numbers you entered are:" << endl;
for (counter = 1; counter <= N; counter++)
{
cin >> number;
cout << number << " ";
switch (number % 2)
{
case 0:
evens++;
if (number = evens)
sumEvens = number + number;
if (number == 0)
zeros++;
break;
case 1:
case -1:
odds++;
if (number = odds)
sumOdds = number + number;
}
}
cout << endl;
cout << "There are " << evens << "Evens" << endl;
cout << "Sum of Evens = " << sumEvens << endl;
cout << endl;
cout << " There are " << odds << " Odds" << endl;
cout << "Sum of Odds = " << sumOdds << endl;
return 0;
}