HW help beginners

So I am a beginner. This is my current HW question.

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.

I know how while loops work and if else statements but figuring out the formula for only read the positive integers is where I am stuck.

Any guidance or help would be appreciated. Thank You!
if ( x >= 0 )
Then it's positive.

Hello esteef,

It is always a good start to include any code you have written. Even if it is not quite right.

Without knowing what you have done this may work or not:
while (std::cout << "\nPrompt: " && std::cin >> num && num > -1).

Post your code. You may get more than you first thought.

Since you are new this will help:


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Andy
an even number is one which has a remainder of 0 when divided by 2. To get the remainder use %.

a % b will give the remainder of a / b
Yes andy you are correct i will do that from now.

Seeplus thank you so much. You are right and I overlooked that. That should help me now.

Topic archived. No new replies allowed.