Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (rocklionmba):

(C) Need help with some code 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 and the sum of all the odd integers read. Declare any variables that are needed.

OpenStudy (rocklionmba):

Currently, I have this: int readnum; int evennum; int oddnum; while(scanf("%d", &readnum) > 0){ if (readnum % 2 == 0){ evennum += readnum; } else { oddnum +=readnum; } } printf("%d %d", evennum, oddnum);

OpenStudy (rocklionmba):

The only thing myprogramminglab is complaning about is evennum, it comes out always 10 less than it should be and I have no idea what exactly is wrong

OpenStudy (karim728):

you have to initialize evennum, evennum

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!