Question: Issue: My Results produce an Endless loop Question: a loop that reads positiveintegersfrom standard input and that terminates when it reads anintegerthat is not positive.

Issue: My Results produce an Endless loop

Question: a loop that reads positiveintegersfrom standard input and that terminates when it reads anintegerthat is not positive. After theloop terminates, it prints out thesumof all the evenintegersread and thesumof all the oddintegersread(The twosumsare separated by a space).Declareanyvariablesthat are needed.

My Code:

int x;

int evenSum = 0;

int oddSum = 0;

cin >> x;

while (x > 0)

if ((x % 2) == 0 && (x > 0))

{

evenSum += x;

}

else

{

oddSum += x;

}

cout

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 Mathematics Questions!