I'm a beginner into C++ and am using CodeLabs (Turing) for homework. I'm working on a problem that states:
"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. Declare any variables that are needed."
Here is my code:
insertI've tested the code using Visual Studio and it works as described, however the results say I have a run-time error and I should be using a > somewhere. I can't figure this out.Code:int n, sum; sum = 0; { cin >> n; while (n % 2 == 0) { sum = n + sum; cin >> n; } if (n % 2 != 0) { cout << sum; } }
Any help would be greatly appreciated. Also I'm not sure if the spacing is going to be edited correctly in this post (there is spacing).