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++;
#include <iostream>
usingnamespace 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;
}