结果: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;
}
答案 0 :(得分:0)
circle
围绕{}
的实施。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;
}