Hey guys, very new to programming and need some help with a homework problem.
Note a few things:
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 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.
- This does not need to be a complete program, just what is asked above.
- This need to be a do-while loop.
- The spaces between the numbers is important, but I don't know how to get spaces.
Here is what I have so far:
Right now, the problem is the program is simply adding up ALL the numbers, not the odd, evens, etc.
int num, sum=0;int sumeven=0;
cin >> num;
if (num % 2 == 0 && num >= 0)
sumeven = sumeven + num;
sum = sum + num;
cout<< sum, sumeven, numeven, totalnum;
Again, I am very new to this so go easy on me .
Thanks in advance!