Examples needed of an application

Could anyone give examples of an application that displays all even numbers from 2 to 100 inclusive , and that starts a new line after every multiple of 20 (20, 40, 60, 80).

Here is what i need to include in my assignment if anyone could talk it through with me, and explain why I need to use certain commands it would be greatly appreciated. Please try and make it simpler though since I am not that advanced.

1. For loop - 2 pt
2. If statement - 2 pt
3. Increment - 2 pt - efficient for what the output is
4. Newline after every multiple - 2
5. Make sure you put in your name, date and project - 2

Thanks in advance,
RGB 455
ignore the name / date / and project because that would be awkward...
Last edited on
For loop has 3 parts, initialization, condition, and increase.
Initialize to your starting value, go to your condition, and increase by your incrementing amount.

If statement will be determining if the variable is a multiple of 20. (Hint: Modulus division)
Last edited on
I am not quite sure how to start a new line after every multiple of 20
are you allowed to use other loops as well or just one of each?




for(int i=2; i<=100 ; i++)
{
if(i%2==0)//modulus division for even number
{
cout<< "\n" << i ;
}
}
Last edited on
@Hardisus what do you mean by other loops or one of each if you mean like merging 2 then I think so.
Are you only allowed to use one for and one if ?

#include <iostream>
using namespace std;

int main()
{
for(int i =1; i<101; i++)
{
if(i%2==0 )
{
cout << i << " ";
if(i%20==0)
{
cout << endl ;
}
}
}

return 0;
}
Topic archived. No new replies allowed.