Loop Factorial

closed account (SwADGNh0)
I am using PLEASE as a beginner to get basic understanding of codes as an intro to c++.
I am stuck on the following question:

"USING A LOOP, multiply all of the numbers between -3 and -8."

the result is supposed to look like:

"total is now -3
total is now 12
total is now -60
total is now 360
total is now -2520
total is now 20160"

Thus far I am limited to using loop like "if" "while" and "else". Please suggest a solution.
closed account (48T7M4Gy)
Please suggest a solution.

I suggest a tutorial like the one here. if, while, etc are all loops and more.

http://www.cplusplus.com/doc/tutorial/control/
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main()
{
    int total=1;
    for(int i=-3;i>=-8;i--)
    {
        total=total*i;
        cout << "total is now " << total << endl;
    }
}
Topic archived. No new replies allowed.