I need to get this program to ignore even numbers and only add positive ODD numbers. The loop is designed to end when the user inputs "-1" and this feature works. The problem I am having is my code doesn't print the show the results of the addition, or when I can get the program to print the results out the number I am getting back is WRONG.
#include <iostream>
usingnamespace std;
int main()
{
int in;
int total = 0;
while (true) {
cout << "Enter a positive odd number or -1 to get quit ";
cin >> in;
if (in <= 0) {
break;
} elseif (in % 2 == 0) {
total += in;
cout << total;
cout << " The total number of odd intergers equals = " << total + in << endl;
}
}
}
I have been working on this but still can't get it add the numbers right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int in;
int total = 0;
while (true) {
cout << "Enter a positive odd number or -1 to get quit ";
cout << "\n";
cin >> in;
if (in <= 0) {
break;
} elseif (!in / 2 == 0) {
total = total + in;
total++;
cout << "The total number of odd intergers equals = " << total << endl;
}
}
}