圆形体体积计算器

在这里插入图片描述在这里插入图片描述

#include<iostream>
#define pi 3.1415926535
using namespace std;
int main(){
    
    
	int n;
	double r,h;
	while(1){
    
    
		cout<<"1-Ball"<<endl<<"2-Cylinder"<<endl<<"3-Cone"<<endl<<"other-Exit"<<endl<<"Please enter your command:"<<endl;
		cin>>n;
		if(n==1){
    
    
			cout<<"Please enter the radius:"<<endl;
			cin>>r;
			printf("%.2lf\n",4*pi*r*r*r/3);
		}
		else if(n==2){
    
    
			cout<<"Please enter the radius and the height:"<<endl;
			cin>>r>>h;
			printf("%.2lf\n",pi*r*r*h);
		}
		else if(n==3){
    
    
			cout<<"Please enter the radius and the height:"<<endl;
			cin>>r>>h;
			printf("%.2lf\n",pi*r*r*h/3);
		}
		else break;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/interestingddd/article/details/114992702