Question: The code does everything I want it to but I can not get it to do the math, of adding the odd and even numbers

The code does everything I want it to but I can not get it to do the math, of adding the odd and even numbers entered at the end. What am I doing wrong?

# include

using namespace std;

main() { int x, y, oddSum = 0, evenSum = 0; char e; do{ cout << "Enter a number or 0 to exit."; cin >> x; } while (x > 0); for (int i = 0; i < x; i++){ cin >> x; if (x == e) break; else if (x % 2 == 0) evenSum += y; else oddSum += y; } cout << "The sum of even numbers: " << evenSum << endl; cout << "The sum of odd numbers: " << oddSum << endl; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!