Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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