### Permutations Assignment Using Double Variables Hi friends! I'm new to C++...in fact, this is my second programming class. I understand a bit of it, but not 100%. My assignment this week is to determine the number of potential team arrangements using the double type variable.

- If there are 18 people in your class and you want to divide the class into programming teams of 3 members, you can compute the number of different teams that can be arranged using this formula (n !⁄r !(n-r)!).

The coding that I have does not create the correct answer and I am also getting an error. Any help is appreciated!!

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` `````` //Include statements #include #include using namespace std; #include #include #include using namespace std; //Global declarations: Constants and type definitions only -- no variables //Function prototypes int main() int main() { //In cout statement below SUBSTITUTE your name and lab number cout << "" << endl << endl; //Variable declarations const double PI = 3.14 double n = 18.0; double r = 3.0; double nmr = 15.0; double nFact = exp(-n) * pow(n, n) * sqrt(2 * PI * n); double rFact = exp(-r) * pow(r, r) * sqrt(2 * PI * r); double nmrFact = exp(-nmr) * pow(nmr, nmr) *sqrt(2 * PI * nmr); //Program logic //using sterlings formula // cout < http://www.cplusplus.com/forum/beginner/92924/
OP is copy-paste spam of a five year old post. Very strange. They went through the trouble of creating a burner account and using the code tags, marking the post as solved, so they actually know how to use this site already. Would have been less effort just to do the assignment.

Is the goal to use this as a add-spam account later on?
Last edited on Hi newbieg...first, THANKS for your quick response!!

I tried that coding and it works perfect to my solution.

My last class was a Visual Basic and made more sense, I'm struggling through this one. So I really appreciate your help :) @j3n1096,
You are falling into the trap of seeing a formula involving factorials for convenience ... and automatically assuming that you need to code it using factorials.

Factorials rapidly overflow integers, whilst using doubles leads to unnecessary floating-point rounding error. And Sterling’s formula is only an asymptotic approximation (for large n). It would be hopeless for 3 factorial.

18C3 is just (18*17*16)/(1*2*3) and that is easily computable in integers.

18!/15! cancels down to 18*17*16 - it is completely unnecessary to work out 18! and 15! separately.
Last edited on
Topic archived. No new replies allowed.