I'm having trouble understanding how to write a function call. This is what I have so far:

#include <ionstream>

using namespace std ;

int binomial(int n, int k) ; // function prototype


int main ()
{
    
    int n, k ; // parameters for the binomial number
    int result ;
    
    cout << endl ;
    
    // read in n & k
    
    cout << "Enter n (positive integer) : " ;
    cin >> k ;
    
    cout << "Enter k (positive integer) : " ;
    cin >> k ;
    
    result = 
    
    cout << "Binomial number " << n << "C" << k
         << " = " << result << endl ;
         
    return (0) ;
}

The function call is supposed to be written following "result =" but I'm not sure how to do this....Any help would be appreciated. Many thanks in advance!!

Recommended Answers

All 3 Replies

Okay, before I answer your question, a few things need to be cleared. In all the code I've seen till now, <ionstream> is by far the most striking alternative to the known, and beloved <iostream> (although, I must admit, ionstream sounds cool).
And another thing is the cin statement at line 19, where you'd probably want to read the input to n , not k ...

Anyway, to answer your question, you'd need to do this: result = binomial(n,k); , assuming that the function binomial is defined somewhere...

Hope this helped :)

Okay, before I answer your question, a few things need to be cleared. In all the code I've seen till now, <ionstream> is by far the most striking alternative to the known, and beloved <iostream> (although, I must admit, ionstream sounds cool).
And another thing is the cin statement at line 19, where you'd probably want to read the input to n , not k ...

Anyway, to answer your question, you'd need to do this: result = binomial(n,k); , assuming that the function binomial is defined somewhere...

Hope this helped :)

Thanks for catching those errors, sometimes I need to slow down lol...anyhoo so if I understand correctly, you're saying my code thus far should read as such:

#include <iostream>

using namespace std ;

int binomial(int n, int k) ; // function prototype


int main ()
{
    
    int n, k ; // parameters for the binomial number
    int result ;
    
    cout << endl ;
    
    // read in n & k
    
    cout << "Enter n (positive integer) : " ;
    cin >> n ;
    
    cout << "Enter k (positive integer) : " ;
    cin >> k ;
    
    result = binomial(n,k); 
    
    cout << "Binomial number " << n << "C" << k
         << " = " << result << endl ;
         
    return (0) ;
}

There is more to this code but I'm still trying to figure this "function call" out first. Could you tell me if the function call you provided will be accurate or could it possibly change after I add the rest of the code?

Nope, that's absolutely fine. You won't need to change the function call, even if you add more code, that is unless and until you change the functions' arguments or something... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.