7-40 圆形体体积计算器 (20分)_题不难但是细节!!

在这里插入图片描述
输入样例:

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:

知识点

  1. #define PI 3.1415926535 (535!!!)
  2. while(1)
  3. 不要忘了break
  4. 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;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DDouble-

你的鼓励是我最大的动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值