Having troubles finding the logic behind questions!

I started learning C++ 3 weeks ago in my Uni class and I have a very dismissive Prof who would insult me rather than answer my question. So I'm in a very depressed state. so far the things I know are for, if, while, do..while.
I figured I might be really stupid or I haven't figured the logic behind programming yet because to be honest, I'm stock with a question like this:
Write a program to print the product of multiplying even numbers from 1 to 10.

I would really appreciate if anyone took the time to help me out.

I could only write this far, and then blank...

1
2
3
4
5
6
 #include <iostream>
using namespace std;
int main()
{
	for(int i=2; i<=10; i+=2)
1
2
3
4
5
6
7
8
int result=1;
for(int i=2; i<=10; i+=2)
{
   result = result * i ;
}

cout << result;



in 1st pass, result = 1*2 = 2
2nd, result = 2 *4 =8
3rd, 8* 6 =48
4th, 48* 8 = 384
5th, 384*10 = 3840
6th, i =12 > 10 so loop ends.
Last edited on
Topic archived. No new replies allowed.