2011-07-19 20 views
2
#include <iostream> 

using namespace std; 

const double PI = 3.14; 

void ReadinputData(int& a, int& b){ 

cout << " Give me the height of the Cylinder: "; 
cin >> a ; 
cout << " Give me the radious of its base: "; 
cin >> b ; 

} 


void ComputetheResults(int a,int b,int &x,int &y){ 

x= 2*PI*b*a; 
y= PI*a*b*b; 

} 

void DisplayAnswers(int a, int b){ 

cout<< "the surface are of the cylinder is: "<< a<< endl; 
cout<< "the volume of the cylinder is: "<< b << endl; 

} 


int main() 
{ 
int h,r,A,V; 
h=0; 
r=0; 
A=0; 
V=0; 
ReadinputData(int h, int r); 
ComputetheResults(int h,int r,int &A,int &V); 
DisplayAnswers(int A,int V); 

} 

エラーは次のとおりです。私の主な機能には、 "intの前に予想される一次式"という種類のエラーがあります。どうしましたか?

--------------ビルド:EEEEでのデバッグ---------------

コンパイル: 'int型のmain()' 関数で: /ホーム/ vaios /デスクトップ/ ertt/eeeeee/EEEE /メイン/home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp main.cppに .cpp:39:15:error: 'int'の前に一次式が必要です。 /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:39:22:エラー: 'int'の前に一次式がありません。 /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:19:error:予期されるprimary-expression beforeの前にint ' /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:25:エラー:' int 'の前に予期した一次式があります。 /home/vaios/Desktop/ertt/eeeeee/eeee/main。 cpp:40:31:error: 'int'の前に一次式が必要です /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:40:38:エラー: 'int'の前に一次式が予期されています /41:16:エラー: 'int'の前に一次式が予期される /home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp:41:home/vaios/Desktop/ertt/eeeeee/eeee/main.cpp: 22:エラー: 'int'の前に予期される一次式 ステータス1(0分、0秒)でプロセスが終了しました エラー8件、警告0件

+1

この種の数学では、 'int'sではなく' float'または 'double'sを使用してください。 'int'sを使うと、非常に不正確な結果になります。 :) –

答えて

1

関数のタイプそれを呼び出すときの引数。

言い換えれば、ライン39は

Readinputdata(h, r); 
3

をお読みくださいあなたは、関数を呼び出す際に、引数のデータ型を再宣言する必要はありません。だから、変更:

ReadinputData(int h, int r); 
ComputetheResults(int h,int r,int &A,int &V); 
DisplayAnswers(int A,int V); 

単純に:それはあなたの現在の未修正のコードで、今現状では

ReadinputData(h, r); 
ComputetheResults(h, r, A, V); 
DisplayAnswers(A, V); 

、あなたは基本的に再宣言している機能の有効な戻り値の型なしmainの内側適切な引数を指定して関数を呼び出すのではなく、それはコンパイラエラーをスローするつもりです。

+0

なぜコンパイルエラーが出るのですか?それは簡単な再宣言ではありませんか? –

+0

他の関数の中で関数を宣言することは、 'g ++'や他のC++コンパイラでサポートされている機能ではなく、C++ 03標準でサポートする必要もありません。これは 'gcc'でサポートされている機能ですが、C言語の拡張機能(ISO C標準ではサポートされていませんが、*できないとは言わなかったので、 'gcc'コンパイラはそれを非標準のC言語拡張として追加しました)。 – Jason

+0

@Ali - 関数が戻り値の型を持っていれば宣言されているはずです。今それは間違っています。 –

1

関数を呼び出すときに引数型を指定しないでください。

ReadinputData(h, r); 
関連する問題