Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this code in java Quiz 5.3: Case Study: Guessing Numbers Worth 3 Points Write a

ID: 3919619 • Letter: T

Question

this code in java

Quiz 5.3: Case Study: Guessing Numbers Worth 3 Points Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. After the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. Declare any variables that are needed Assume the availability of a variable, stdin, that references a Scanner object associated with standard input.

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

// your code goes here

int num;

int sum1=0;

int sum2=0;

int ct1=0;

int ct2=0;

cin>>num;

while(num>0)

{ if(num%2==0)

{ct1++;

sum1 += num;

}

else

{ct2++;

sum2 += num;

}

cin>>num;

}

cout<<"Sum of even integers "<<sum1<<" ";

cout<<"Sum of odd integers "<<sum2<<" ";

cout<<"Number of even integers "<<ct1<<" ";

cout<<"Number of odd integers "<<ct2;

return 0;

}