Hi all,
i am just asking for help to make this code work, i wrote it but it just tell me "too many arguments for Binomal Function" What should i change ?

#include <iostream>
#include <cmath>
using namespace std;
long factorial (long);
long binomal (long);

int main()
{
    int x, y,n,k ;
    cout << "Enter x:" <<endl;
    cin >> x;
    cout << "Enter y :" <<endl;
    cin >> y;
    cout << "Enter n :" <<endl;
    cin >> n;
    cout << "Enter k :"<<endl;
    cin >> k;
    binomal(x,y,n,k);
}
long factorial(long j)
{
    long f = 1;
    for(long i=1 ; i<=j ; i++)
    {
        f*=i;
    }
    return f;
}
long binomal(long x , y , n , k)
{
    for(k=0;k=n;k++)
    {
        long result = 0 ;
        result = (factorial(n))/(factorial(k)*factorial(n-k))*pow(x,n-k)*pow(y,k);
    }
    return result;
}

Thanks.

Line 5: You give a forward refrence to the function taking only one long

your actual function wants 4 and you pass 4 so change it to be

long binomal(long, long, long, long);

//also change the actual function to include the names of the vars as i find it to be better practise
long binomal(long x, long y, long n, long k);

This will fix the problem :)

edit: i assumed you wanted all longs but if you want ints or the likes change the var type in the function to int or whatever.

k looks like it is an int so it would be

long binomal(long, long, long, int);

long binomal(long x, long y, long n, int k);

Edited 6 Years Ago by Kanoisa: n/a

Thank you for the help , But it tells me ;" Result was not declared on the scope" ?
EDIT ; i solved the result declaration problem, the program launch i enter the Values but it return Nothing ?
sorry for my pertinence and load of questions...

Edited 6 Years Ago by SkonTeam: n/a

Take result and its initilisation out of the for loop. the result variable is created in the foor loop and destroyed after the loop so you cannot return it. try this

long result = 0 ;
    for(k=0;k=n;k++)
    {
        
        result = (factorial(n))/(factorial(k)*factorial(n-k))*pow(x,n-k)*pow(y,k);
    }
    return result;

also you would be resetting result to 0 each iteration of that for loop is this what you intended? The above code i posted for the function does not reset the result each iteration of the loop. to do that add result = 0 at the start of the for loop as before without int before its name.

I managed to make it work but when the values are in it don't show the result. Any suggestions ?

Sorry for the double post,i haven't found the edit button.
Ok i found the problem and solved it thank you for your help :
it was in the [binomal loop] :

for(long k=0;k<=n;k++)
    {
        result = ((factorial(n))/(factorial(k)*factorial(n-k)))*pow(x,n-k)*pow(y,k);
        sum+=result;
    }

Edited 6 Years Ago by SkonTeam: n/a

This question has already been answered. Start a new discussion instead.