Microsoft Developer Network > 포럼 홈 > Visual C++ Language > Receiving C2447 error - unable to correct error
질문하기질문하기
 

답변됨Receiving C2447 error - unable to correct error

  • 2007년 12월 2일 일요일 오전 1:38New to C__ 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I am a new to C++ and I am completing an exercise in C++.  I have read my text and online materials to see if I can correct the error.  I have tried everything that I know to correct the problem, but no luck.

    I don't understand what is meant by missing function header?  This is the error details: error C2447: '{' : missing function header (old-style formal list?) which occurs a line 60 (the red bracket below). 

     

    Any guidance is helpful.

    Chris  

     

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

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

    int _tmain(int argc, _TCHAR* argv[])

    {

    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) ;

    }

    // ********************************************************

    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 <![endif]>

    if (n < k)

    {

    return(0) ;

    }

    else

    {

    denominator = 1 ; // initial value <![endif]>

    for (i = 1 ; i <= k ; i = i+1)

    denominator = denominator * 1 ; <![endif]>

    for (i = n-k+1 ; i <= n ; i = i+1)

    numerator = numerator * i ; <![endif]>

    return (numerator/denominator) ;

    } // else

    }

답변

  • 2007년 12월 2일 일요일 오전 1:48Andreas Masur 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Simply remove the ';' sign at the end of your definition for 'binomial'...

    // ********************************************************

    int binomial ( int n, int k ) ;                              <-- Remove the ';' right here

    /* Computes the binomial coefficient nCk */

    /* */

    /* Inputs: */

    /* n, k (integers) */

    /* */

    /* Output: */

    /* binomial coefficient nCk (integer) */

    {

    int numerator, denominator ;

    int i ; // needed to compute numerator & denominator <![endif]>

    if (n < k)

    {

    return(0) ;

    }

    else

    {

    denominator = 1 ; // initial value <![endif]>

    for (i = 1 ; i <= k ; i = i+1)

    denominator = denominator * 1 ; <![endif]>

    for (i = n-k+1 ; i <= n ; i = i+1)

    numerator = numerator * i ; <![endif]>

    return (numerator/denominator) ;

    } // else

    }


  • 2007년 12월 2일 일요일 오후 5:47Andreas Masur 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Well...you have some '<![endif]>' clauses in your code that the compiler certainly cannot understand. Please find below a cleaned-up version of your function:

    Code Block

    int binomial( int n, int k )

    {

      int numerator, denominator;

      int i;


      int(n < k)

      {

        return (0);

      }

      else

      {

        denominator = 1;

        for( i = 1; i <= k; i = i + 1)

          denominator = denominator * i;


        for( i = n-k+1; i <= n; i = i + 1)

          numerator = numerator * i;


        return (numerator/denominator);

      }

    }


  • 2007년 12월 3일 월요일 오전 9:55Pintu Shukla 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hello Andreas ,
    This code contain few error .have a look on the bold Line

     Andreas Masur wrote:
    Well...you have some '<![endif]>' clauses in your code that the compiler certainly cannot understand. Please find below a cleaned-up version of your function:

    Code Block

    int binomial( int n, int k )

    {

      int numerator, denominator;

      int i;


      int(n < k) // i think it is if(n<k) instead of int

      {

        return (0);

      }

      else

      {

        denominator = 1;

        for( i = 1; i <= k; i = i + 1)

          denominator = denominator * i;


        for( i = n-k+1; i <= n; i = i + 1)

          numerator = numerator * i; // Unexpected result .Because numerator is not initialized


        return (numerator/denominator);

      }

    }


모든 응답

  • 2007년 12월 2일 일요일 오전 1:48Andreas Masur 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Simply remove the ';' sign at the end of your definition for 'binomial'...

    // ********************************************************

    int binomial ( int n, int k ) ;                              <-- Remove the ';' right here

    /* Computes the binomial coefficient nCk */

    /* */

    /* Inputs: */

    /* n, k (integers) */

    /* */

    /* Output: */

    /* binomial coefficient nCk (integer) */

    {

    int numerator, denominator ;

    int i ; // needed to compute numerator & denominator <![endif]>

    if (n < k)

    {

    return(0) ;

    }

    else

    {

    denominator = 1 ; // initial value <![endif]>

    for (i = 1 ; i <= k ; i = i+1)

    denominator = denominator * 1 ; <![endif]>

    for (i = n-k+1 ; i <= n ; i = i+1)

    numerator = numerator * i ; <![endif]>

    return (numerator/denominator) ;

    } // else

    }


  • 2007년 12월 2일 일요일 오전 1:58New to C__ 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Thanks for the reply, but now I have additional errors regarding missing ';" before <

    Simply remove the ';' sign at the end of your definition for 'binomial'...

    // ********************************************************

    int binomial ( int n, int k ) ;                              <-- Remove the ';' right here

    /* Computes the binomial coefficient nCk */

    /* */

    /* Inputs: */

    /* n, k (integers) */

    /* */

    /* Output: */

    /* binomial coefficient nCk (integer) */

    {

    int numerator, denominator ;

    int i ; // needed to compute numerator & denominator <![endif]>

    if (n < k)

    {

    return(0) ;

    }

    else

    {

    denominator = 1 ; // initial value <![endif]>

    for (i = 1 ; i <= k ; i = i+1)

    denominator = denominator * 1 ; <![endif]>

    for (i = n-k+1 ; i <= n ; i = i+1)

    numerator = numerator * i ; <![endif]>

    return (numerator/denominator) ;

    } // else

    }

     

     

  • 2007년 12월 2일 일요일 오전 2:06Andreas Masur 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
     C++ Student wrote:

    Thanks for the reply, but now I have additional errors. 


    Well...and the errors are? The removal only fixes the error you posted about before. Certainly any other error in your code following this ';' sign is still there and raises not error since the first one is fixed... 
  • 2007년 12월 2일 일요일 오후 5:07New to C__ 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    I reviewed the error codes with the online help.  Tried to correct the errors, but with no success.

    #include "stdafx.h"

    #include <iostream>

    using namespace std;

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

    int _tmain(int argc, _TCHAR* argv[])

    {

    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) ;

    }

    // ********************************************************//

    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 <![endif]>

    if (n < k)

    {

    return(0) ;

    }

    else

    {

    denominator = 1 ; // initial value <![endif]>

    for ( i = 1 ; i <= k ; i = i + 1)

    denominator = denominator * i;<![endif]>

    for (i = n-k+1 ; i <= n ; i = i + 1) //line 76.  Four errors:  warning C4552: '<=' : operator has no effect; expected operator with side-effect;

    error C2143: syntax error : missing ';' before ')';  error C2143: syntax error : missing ';' before ')';  error C2143: syntax error : missing ';' before '<'

    numerator = numerator * i;<![endif]>

    return (numerator/denominator);

    } // else

    }

     

    Thanks,

    Chris

  • 2007년 12월 2일 일요일 오후 5:47Andreas Masur 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Well...you have some '<![endif]>' clauses in your code that the compiler certainly cannot understand. Please find below a cleaned-up version of your function:

    Code Block

    int binomial( int n, int k )

    {

      int numerator, denominator;

      int i;


      int(n < k)

      {

        return (0);

      }

      else

      {

        denominator = 1;

        for( i = 1; i <= k; i = i + 1)

          denominator = denominator * i;


        for( i = n-k+1; i <= n; i = i + 1)

          numerator = numerator * i;


        return (numerator/denominator);

      }

    }


  • 2007년 12월 2일 일요일 오후 9:44New to C__ 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    Yes, the <![endif]> clauses were the problem.  The code ran when the <![endif]> clauses were removed.

     

    A good lesson learned.

     

    Thanks very much!

     

    Chris

  • 2007년 12월 3일 월요일 오전 9:55Pintu Shukla 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    Hello Andreas ,
    This code contain few error .have a look on the bold Line

     Andreas Masur wrote:
    Well...you have some '<![endif]>' clauses in your code that the compiler certainly cannot understand. Please find below a cleaned-up version of your function:

    Code Block

    int binomial( int n, int k )

    {

      int numerator, denominator;

      int i;


      int(n < k) // i think it is if(n<k) instead of int

      {

        return (0);

      }

      else

      {

        denominator = 1;

        for( i = 1; i <= k; i = i + 1)

          denominator = denominator * i;


        for( i = n-k+1; i <= n; i = i + 1)

          numerator = numerator * i; // Unexpected result .Because numerator is not initialized


        return (numerator/denominator);

      }

    }


  • 2007년 12월 8일 토요일 오전 4:22Voltronx 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

     

    I would like to add an error message similar to the one below that would stop the program and recall the function if the problem would result in an overflow error. 

     

    if (n < k)

    {

    cout <<"ERROR!! n must be larger than k."<<endl ;

    return (0) ;

    }

     

    Your input would be greatly appreciated.
  • 2007년 12월 8일 토요일 오후 12:18Pintu Shukla 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
     Voltronx wrote:

     

    I would like to add an error message similar to the one below that would stop the program and recall the function if the problem would result in an overflow error. 

     

    if (n < k)

    {

    cout <<"ERROR!! n must be larger than k."<<endl ;

    return (0) ;

    }

     

    Your input would be greatly appreciated.


    Hello Voltronx this will defenately show you the message but but will not recall the function .if you want that your program will work according to your logic .then you should use a do..while loop inside your program like shown in the following example

    Code Block

    do{

    //write your code here

    }while(n<k);



    Thanx