2016-05-15 2 views
-4

結果計算します。誰も私が数日ループを学ぶことから、 は私が 特にプロトコルのループ部分にその を行うためにループを使用する方法を理解していないresultなどの円の面積(ループに)

をすることができます助けて?

私のコード:enter link description here

#include <iostream> 
#include <iomanip> 
using namespace std; 
const double PI = 3.14159265; 
void circle(int r1, int r2, double &d, double &c, double &a) 
for(int i=r1;i<=r2;i++) 
{ 
    { 
    d=2*i; 
    c=2*PI*i; 
    a=PI*i*i; 
    } 
} 

int main(){ 
double d, c, a; 

int r1, r2; 
int r; 
cout<<"enter 1st no."; 
cin>>r1; 
cout<<"enter 2nd no."; 
cin>>r2; 

cout << endl; 
cout << setw(6) << "Radius"; 
cout << setw(10) << "Diameter"; 
cout << setw(15) << "Circumference"; 
cout << setw(10) << "Area" << endl; 

circle(r1, r2, d, c, a); 
for (int i=r1;i<=r2; i++) 
{ 
    cout<< setw(6)<<i<< setw(10)<<d<< setw(15)<<c<< setw(10)<<a<<endl; 
} 

return 0; 
} 
+3

あなたは、 "プロトコルのループ部" とは何を意味するのですか?あなたは何を理解していませんか?コンパイラエラーはありますか?このコードは何をしていないのですか? – user463035818

+0

あなたのコードはコンパイルされますか? – orbitcowboy

+0

コードが動作しますが、私は実際にループを使って直径、周囲および面積を計算することを知らない。 – oid

答えて

0
  • あなたは{}circleのimplementionを囲むように持っています。
  • の中に結果を更新して印刷する必要があります。
  • circleはループを必要としません。
  • サンプルと一致する正しい形式。

これを試してみてください:

#include <iostream> 
#include <iomanip> 
using namespace std; 
const double PI = 3.14159265; 
void circle(int i, double &d, double &c, double &a){ 
    d=2*i; 
    c=2*PI*i; 
    a=PI*i*i; 
} 

int main(){ 
    double d, c, a; 

    int r1, r2; 
    int r; 
    cout<<"Please enter the starting radius: "; 
    cin>>r1; 
    cout<<"Please enter the ending radius: "; 
    cin>>r2; 

    cout << endl; 
    cout << setw(6) << "Radius"; 
    cout << setw(10) << "Diameter"; 
    cout << setw(15) << "Circumference"; 
    cout << setw(10) << "Area" << endl; 

    for (int i=r1;i<=r2; i++) 
    { 
     circle(i, d, c, a); 
     cout<< fixed<<setprecision(2)<<setw(6)<<i<< setw(10)<<d<< setw(15)<<c<< setw(10)<<a<<endl; 
    } 
    cout << "Press any key to continue . . ." << endl; 

    return 0; 
} 
+0

oic、今起こっていることは分かっています、ありがとう – oid

関連する問題