7 Replies - 384 Views - Last Post: 14 August 2011 - 09:41 AM Rate Topic: -----

#1 scoobydoobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-August 11

How to declare function call?

Posted 14 August 2011 - 07:46 AM

This is for a homework assignment. I'm working on a code that incorporates a function call and determines the binomial coefficients of n and k. I've corrected several of the errors, but keep getting "error C3861: 'function': identifier not found" when I compile the code. I used "foo", "int foo", and "function" to try and compile the program but no luck. The beginning portion of the code is as follows:

#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 = Need function call (n, k) ;

   cout << "Binomial number " << n << "C" << k
        << " = " << result << endl ;

   return (0) ;
}


Can someone point me in the right direction? Am I not declaring the function properly?

Thanks in advance.

MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 14 August 2011 - 09:39 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to declare function call?

#2 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

Re: How to declare function call?

Posted 14 August 2011 - 08:00 AM

First of all use [ code ] [ /code ] tags to format your code properly on the forum.
Second of all don't you think that this line:

result = Need function call (n, k) ;



looks only half finished? You've written a function prototype for a function called binomial(int n, int k), so I suspect that it's the one you're trying to call?
Assuming that you've written the function you should call it like this:
result = binomial(n, k);


Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon

Reputation: 3057
  • View blog
  • Posts: 9,303
  • Joined: 25-December 09

Re: How to declare function call?

Posted 14 August 2011 - 08:01 AM

First use code tags when posting code.

Second show how you are trying to:
1. Declare the function.
2. Implement the function.
3. Call the function.

Jim
Was This Post Helpful? 0
  • +
  • -

#4 scoobydoobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-August 11

Re: How to declare function call?

Posted 14 August 2011 - 08:21 AM

Okay, that took care of that error; however, when I compile the code now, I get two new errors: "error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup" and "fatal error LNK1120: 1 unresolved externals." The called environment looks like this:

int binomial(int n, int k)

/* Computes the binomial coefficient nCk */
/* */
/* Inputs:                               */
/*    n, k (integers)                    */
/*                                       */
/* Output:                               */
/*    binomial coefficient nCk (integer) */

{
   int numerator, denominator ;
   int i ; // needed to compute numerator & denominator

   if ( n < k )
   {
     return(0) ;
   }
   else 
   {
	  denominator = k ;
	   for (i = 1 ; i <= k ; i++)
		denominator =  denominator * i ;
          numerator = n ;
	   for (i = 1 ; i >= n ; i ++)
	    numerator = numerator / i ;
      return ( numerator / denominator ) ;
   }
}


Again, this is a homework assignment and I'm not looking for the answer. I just need to know where my errors are so I can fix them. Thanks Jim and Mathias.

This post has been edited by JackOfAllTrades: 14 August 2011 - 09:40 AM
Reason for edit:: Fixed code tags

Was This Post Helpful? 0
  • +
  • -

#5 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

Re: How to declare function call?

Posted 14 August 2011 - 08:26 AM

This is a linking error so it has nothing to do with your code.

Rather it looks like you've built the project wrong. Try creating a new project and copy/paste the old code into the new project and make sure you choose to create a console application.
Was This Post Helpful? 0
  • +
  • -

#6 scoobydoobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 14-August 11

Re: How to declare function call?

Posted 14 August 2011 - 08:31 AM

Mathias,

Thanks, I was finally able to compile. Why choose console application over win32 project? Just curious what the difference is. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#7 MathiasVP  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 154
  • Joined: 08-August 10

Re: How to declare function call?

Posted 14 August 2011 - 08:38 AM

Basically you have 2 options (Actually you have more, but let's leave it at 2 for now) when choosing your project:

Console applications and Win32 applications.

Console applications are, like yours, run with a command line interface like you see in your own application. This type of application has it's entry point in the main() function.

On the other hand you have Win32 applications, which is used to create programs that has the "Windows"-feeling to it. You can read alot more about Win32 applications here.
These applications has it's entry point in the WinMain() function and generally focuses on the concept of the message loop.
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,528
  • Joined: 23-August 08

Re: How to declare function call?

Posted 14 August 2011 - 09:41 AM

The RIGHT way to use code tags:

:code:

If that's too complicated, see the link my signature.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1