Only adding odd numbers

So I have got these integers to add up and give the sum but I'm not sure how to place it so that only odd numbers can be added in and they can only input 10 odd numbers. Any and all help is appreciated.

#include <iostream>
using namespace std;
int main()
{
int i;
int counter = 0;
int sum = 0;
while(counter != 1){ //not sure what value to set this not equal to
cout << "Enter an odd number:";
cin >> i;
if( i > 0){
sum += i;
}
else counter++;

}
cout << "the sum is: " << sum;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
int main()
{
int i;
int counter = 0;
int sum = 0; 
while(counter < 10){ // changed to counter < 10
cout << "Enter an odd number:";
cin >> i;
if(i % 2 == 1){ // modified this if... else statement
sum += i;
counter++;
}
else
cout << "That was not an odd number" << endl;

}
cout << "the sum is: " << sum; 
return 0; 
}
Last edited on
Topic archived. No new replies allowed.