My program is suppose to read positive and odd numbers and add their sums but any negative numbers they are not suppose to count or be added to the sum. My error message is coming up when I type a negative number in but I think it's still being counted and added to the sum. Can someone take a look and help me out?
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main ()
{
int number1;
int sumeven=0;
int sumodd=0;
int evencounter=0;
int oddcounter=0;
int counter;
cout<<"Please enter 10 integers: \n";
for( counter=1; counter<=10; counter++)
{
cin>> number1;
if (number1 % 2 == 0)
{
evencounter++;
sumeven=sumeven+number1;
}
else
{
oddcounter++;
sumodd=sumodd+number1;
}
if (number1 < 0)
cout<<"One number is invalid. Enter positive number: \n"<<number1;
}
cout<<"There are " <<evencounter<<" even numbers \n ";
cout<< "and the sum of all even numbers is: \n"<<sumeven;
cout<<"\nThere are " <<oddcounter<<" odd numbers \n";
cout<< "and the sum of all odd numbers is: \n"<<sumodd;
return 0;
}