• サインイン
  • Microsoft.com
  • 日本 (日本語)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)United States (English)Россия (Русский)대한민국 (한국어)香港特别行政區 (中文)台灣 (中文)中华人民共和国 (中文)
 
 
MSDN
 
 
ホーム
 
 
ライブラリ
 
 
ラーニング
 
 
ダウンロード
 
 
サポート
 
 
コミュニティ
 
 
フォーラム
 
 
MSDN サイト マップ
 
 
 
MSDN > フォーラム ホーム > Visual C++ Language > Receiving C2447 error - unable to correct error
質問する質問する
フォーラムを検索:
  • Visual C++ Language フォーラムの検索 Visual C++ Language フォーラムの検索
  • MSDN フォーラム全体の検索 MSDN フォーラム全体の検索
 

回答済みReceiving C2447 error - unable to correct error

  • 2007年12月2日 1:38New to C__ ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0

    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 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    参考になった投稿として投票
    0
    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日 17:47Andreas Masur ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    参考になった投稿として投票
    0
    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 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    参考になった投稿として投票
    0
    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:58New to C__ ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0

    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 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0
     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日 17:07New to C__ ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0

    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日 21:44New to C__ ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0

    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月8日 4:22Voltronx ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0

     

    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 ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    参考になった投稿として投票
    0
     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
    • 返信返信
    • 引用引用
     
フォーラムに関するヘルプ (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
プロファイル (個人情報) の管理
|
お問い合わせ先
|
MSDN Flash ニュースレター
|
日本での個人情報の取り扱い
|
サイトマップ
|
使用条件
|
商標
|
プライバシー