![]() |
|
#1
|
|||
|
|||
Too few parameters in call to 'factorial(int,int)'Hi, I got problem in my code.
could anyone help me this? I think this is not that hard for someone but it's hard for me.. my purpose and code below; <purpose> The binomial coefficient is defined as n!/(k!(n-k)! when n and k are nonnegative integers, and 0<=k<=n. If n<0,k<0 or k>n , the binomial coefficient is considered to be zero. Also, n=0 and k=0 is considered to be 1. CPP / C++ / C Code:
thank you. Last edited by LuciWiz : 24-Mar-2009 at 04:29.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Too few parameters in call to 'factorial(int,int)'First you declare factorial to take two arguments as described below
Code:
Code:
Either change your declaration (and definition) of factorial to be something like Code:
__________________
My personal site: Utilities for text processing, debugging, testing and plotting |
|
#3
|
|||
|
|||
Re: Too few parameters in call to 'factorial(int,int)'thank you for your answer.
I still have a question that I have to consider about two parameter such as n,k. That's why I mentioned two parameters in the factorial function. So, how can I handle two parameters in my code? Do I have to declare another factorial fuction for k? |
|
#4
|
|||
|
|||
Re: Too few parameters in call to 'factorial(int,int)'A function is non-changing; its definition is compiled to a concrete set of instructions that will always execute the same way given the same parameters. If you wish to have separate behaviors, then you must create separate functions.
For example: CPP / C++ / C Code:
Will not do the same thing as CPP / C++ / C Code:
CPP / C++ / C Code:
__________________
My personal site: Utilities for text processing, debugging, testing and plotting |
|
#5
|
|||
|
|||
Re: Too few parameters in call to 'factorial(int,int)'I'd just like to point out that your factorial function doesn't actually calculate any factorials, as one would assume from it's name. You would also do well to think about what actually is happening in your recursive calls.
This is what happens (I'll just assume small numbers of n = 3, k = 1. Guess we also have to assume you pass k as the second argument): Code:
The solution is simple: Create a factorial function that actually calculates the factorial and nothing else. Then you can write simply CPP / C++ / C Code:
Your while loop is also infinite, since flag never changes inside it. |
|
#6
|
|||
|
|||
Re: Too few parameters in call to 'factorial(int,int)'Thank you very much L7sqr and Kimmo!
I got all of my problems! |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can you call a constructor within a destructor, or vise vesa? | warrener | C++ Forum | 0 | 10-Jun-2008 21:24 |
| Two bugs in my program that just won't go away. | randomperson133 | Assembly Language | 1 | 23-Mar-2008 08:04 |
| Default parameters | ajbharani | C++ Forum | 13 | 15-Dec-2007 14:32 |
| Will pay through Paypal if somebody helps me. | paritoshcool | Assembly Language | 0 | 27-Nov-2007 23:27 |
| Need Help with input files. | Efferus | C++ Forum | 2 | 24-Nov-2007 17:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The