输入样例:
1
2
3
2.4 3
0
输出样例:
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
Please enter the radius:
33.51
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
Please enter the radius and the height:
18.10
1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
知识点
- #define PI 3.1415926535 (535!!!)
- while(1)
- 不要忘了break
- 4.0/3PIrrr); //4.0!!
1.0/3PIrrh); //1.0!!!
5.如果是其他数,程序运行结束:default:return 0;
代码
#include<iostream>
using namespace std;
/*题目不难但是有一个坑,就是这个π的值一定要精确到小数后10位,
要不然只是16分一直有一个测试点错误*/
#define PI 3.1415926535
double r,h;
int n;
int main(){
while(1){
printf("1-Ball\n2-Cylinder\n3-Cone\nother-Exit\nPlease enter your command:\n");
cin>>n;
switch(n)
{
case 1:
printf("Please enter the radius:\n");cin>>r;
printf("%.2lf\n",4.0/3*PI*r*r*r); //4.0!!
break;
case 2:
printf("Please enter the radius and the height:\n");cin>>r>>h;
printf("%.2lf\n",PI*r*r*h);
break;
case 3:
printf("Please enter the radius and the height:\n");cin>>r>>h;
printf("%.2lf\n",1.0/3*PI*r*r*h); //1.0!!!!
break;
default:
return 0;
}
}
return 0;
}