Help with factorial!

Hey guys, so I'm trying to make it so that my factorial variable chooses the number of the cust variable and uses the factorial equation on it.

When I print the factorial, to see if it is working correctly -- it doesn't seem to be. I get:

1
2
2
6
12
12
48
144
288
288
1440
5760
17280
34560
34560
207360



And it goes on and on and on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Problem #2
double sigma=3, cust,rate, factorial=1, x;

for(cust=1;cust<=10;cust++)
{
                          
                          for(x = cust; x >= 1; x--)
                                             {
                                             factorial=factorial*x;
                                             cout<<factorial<<endl;
                                             }
                          //rate=(pow(sigma,cust)*exp(-sigma))/factorial;
                          //cout<<rate<<endl;
                          
}


system("PAUSE");
return 0;
}



The ultimate goal is to have it so that the rate equation gets used 10 times but having to calculate a different factorial from CUST 1-10.

I probably didn't explain it to well but I hope you know what I'm talking about, worst case I could type out the problem I am working on.


Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Problem #2
double sigma=3, cust,rate, factorial=1, x;

cout<<factorial<<endl;
++factorial        //seting to 2
cout<<factorial<<endl;

for(cust=1;cust<=10;cust++)
     for(x = cust; x >= 1; x--) {
           factorial *= factorial;  //multiples with rezult each time
           cout<<factorial<<endl;
      }
return 0;
}
Last edited on
Thanks for the reply!

I just copied this code and the output doesn't match up with what i'm asking o_O. This multiplies numbers like 4*4=16 16*16 = 256 256*256 = ect..

I'm talking about factorials, so its 4! 4*3*2*1 or 6! 6*5*4*3*2*1.
lol sory I feal so stupid now :D

1
2
3
4
5
6
7
8
int main() {
double factorial = 6; // 6!
    for(int x = factorial - 1; x >= 1; --x) {
        factorial *= x;
        cout << factorial << endl;
    }
       return 0;
}
@lirik

Here is your code made to show the factorials.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Factorial.cpp : Defines the entry point for the console application.
// Problem #2

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	double sigma=3, cust,rate, factorial=1, x;

	for(cust=1;cust<=10;cust++)
	{
		factorial = 1;
		for(x = cust; x >= 1; x--)
			factorial=factorial*x;
		cout << "cust = " << cust << " : " << factorial << endl;
		
		//rate=(pow(sigma,cust)*exp(-sigma))/factorial;
		//cout<<rate<<endl;

	}


	system("PAUSE");
	return 0;
}

Since you never reset the factorial to 1 for each of the 10, the numbers kept climbing. I added some text to show the value of each.
Thank You whitenite... it was a rough draft I was going to make it more organized and readable later.

But ya, not resetting the factorial back to 1 was my issue, doh :(
Hmm ^^...

I wish I could delete my posts, being idiot two times in a row.
Haha don't worry about it, all good :P
Topic archived. No new replies allowed.