Use the mod, %. example 8%2=0, so 8 is even. 2 go into 8 evenly, with nothing left over, but 9%2 would equal 1. 9 is odd. Hope this gets you closer to the a solution.
#include <iostream>
usingnamespace std;
int main ()
{
cout<<"these are the evens bettwen of 0 and 20:"<<endl;
for(int i=0;i<=20;i++)
{
if(i%2!=0)
{
continue;
cout<<i<<endl;
}
cout<<"even:"<<i<<endl;
}
}
Run the program and tell me if it helped you,because if it isnt helped you,i will code your program again if wants.
@skarla
I have learned for myself that you ought to compile and run your program before pressing 'submit'.
Also, it does not help people to do their assignments for them. (Particularly if the answer is wrong -- it confuses them more than anything.)
@ATMOSF3AR
The mathematical property of even numbers is: they are evenly divisible by 2.
In a computer program, you can check whether a number has any remainder by using the 'modulo' (or 'remainder') operator; in C++ that's the percent sign: %.
1 2 3 4 5
for (int i = 1; i <= 5; i++)
cout << i << " / 2 has a remainder of " << (i % 2) << "\n";
1 / 2 has a remainder of 1
2 / 2 has a remainder of 0
3 / 2 has a remainder of 1
4 / 2 has a remainder of 0
5 / 2 has a remainder of 1
The trick is to make yourself a loop that goes 1 to 20, and inside that loop check if a number / 2 has a remainder of... zero! If it does, you can print the number.
Your program produces correct output, but I think that is more from luck than anything else. It is malformed:
You are testing for and acting on odd numbers, not even.
You use an unnecessary continue.
You have a line of code that can never be executed.
Maybe you are trying to confuse the OP?
[edit] I don't really mean to be harsh. I'm having a bad day. But I stand by the facts that (1) your code is not clear and (2) you are endeavoring to hand a solution to the OP.
Why are you so intent on derailing this thread?
For a 15-day old program, it isn't bad.
For help to another user, it reeks.
Take a hint and learn something yourself.
It's somewhat refreshing to see a different approach to solve the same problem. There are, of course, many ways to get the "right" output. However, I agree with Duoas. It's logically different than the problem statement for no good reason. Numbers between 1 and 20, but 0 is being tested...