2016-08-03 9 views
-2
#include<iostream> 
#include<cstdlib> 
#include<cmath> 

using namespace std; 
int round(double number); 
int main() 
{ 
    double doublevalue; 
    char ans; 
    do 
    { 
    cout << "Enter the double value:"; 
     cin >> doublevalue; 
    cout << "Rounded that number is"<<round(doublevalue)<<endl; 
    cout << "Again?(y/n)"; 
    cin >> ans; 
     }while(ans=='y' ||ans=='Y'); 
     cout << "End of testing.\n"; 
     return 0; 
     } 
     int round(double number) 
     { 
     return static_cast<int>(floor(number+0.5)); 
    } 

エラーの以下の通りです:は、端末

roundoff.cpp:6:24: error: new declaration ‘int round(double)’ 
    int round(double number); 
        ^
In file included from /usr/include/features.h:374:0, 
      from /usr/include/x86_64-linux-gnu/c++/4.8/bits/os_defines.h:39, 
      from /usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h:426, 
      from /usr/include/c++/4.8/iostream:38, 
      from roundoff.cpp:1: 
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:309:1: error: ambiguates  old declaration ‘double round(double)’ 
__MATHCALLX (round,, (_Mdouble_ __x), (__const__)); 

^ roundoff.cpp: roundoff.cpp: 'int型ラウンド(ダブル)' 関数では22:24 :エラー:新しい宣言 'int round(double)' int round(double number) ^ /usr/include/features.h:374:0からファイルに含まれる、/ usr/include/x86_64-linux-の /usr/include/x86_64-linux-gnu/C++/gnu/C++/4.8/bits /os_defines.h:39、 4.8/bits /c++config.h:426、 /usr/include/c++/4.8/iostream:38, from roundoff.cpp:1: /usr/include/x86_64-linux-gnu/bits/mathcalls.h:309:1:エラー:古い宣言を「二重ラウンド(double)」にあいまいにします。 MATHCALLX(round、(Mdouble __x)、(__const)); ^

+0

コードをフォーマットしてください。このように読むのは難しいです。 – elyashiv

+1

['std :: round'](http://en.cppreference.com/w/cpp/numeric/math/round)を参照してください。公平であるために、C++は 'cmath'がグローバル名前空間に' round'を入れることを許していますので、 'namespace std; 'を使わなくても同じエラーを得ることができます。 – juanchopanza

+0

デュープハンマーの悪用が回復しました。 –

答えて

0

すでに同じ署名があいまいさを引き起こしてroundと呼ばれるメソッドを定義してroundcmathので、あなたは、あなたの関数の名前を変更する必要があります。 roundではなく、名前をmy_round(double number)に変更しても問題ありません。

+0

よろしくお願いします。 –