Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago