Answered step by step
Verified Expert Solution
Link Copied!

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

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

Step: 3

blur-text-image

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions