Question
I can not get this to add the odd and even numbers? This is what I have. # include using namespace std; main() { int
I can not get this to add the odd and even numbers? This is what I have.
# include
using namespace std;
main() { int x, y, oddSum = 0, evenSum = 0; char e; do{ cout << "Enter a number or e to exit."; cin >> x; } while (x > e); for (int i = 0; i < x; i++){ cin >> x; if (x % 2 == 0) y = evenSum; evenSum += y; if(x % 2 == 1) oddSum += y; else if (x == e) break; else cout <<" Good Bye." << endl; } cout << "The sum of even numbers: " << evenSum << endl; cout << "The sum of odd numbers: " << oddSum << endl; }
the output is :
Enter a number or e to exit. 5
Enter a number or e to exit. 6
Enter a number or e to exit. 3
Enter a number or e to exit. 1
Enter a number or e to exit.e
The sum of even numbers: 0
The sum of odd numbers: 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started