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
Get step-by-step solutions from verified subject matter experts
