33,311
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<math.h>
int main() {
int choice;
double pi = 3.14,r,h;
while (1){
printf("1-Ball\n");
printf("2-Cylinder\n");
printf("3-Cone\n");
printf("other-Exit\n");
printf("Please enter your command:\n");
scanf_s("%d", &choice);
if (choice < 1 || choice>3) {
break;
}
switch (choice) {
case 1:
printf("Please enter the radius:\n");
scanf_s("%lf", &r);
if (r <= 0) {
break;
}
printf("%.2f\n", (4.0 / 3) * pi*r*r*r);
break ;
return 1;
case 2:
printf("Please enter the radius and the height:\n");
scanf_s("%lf %lf", &r, &h);
if (r <= 0 || h <= 0) {
break ;
}
printf("%.2f\n", pi*r*r*h);
break ;
return 1;
case 3:
printf("Please enter the radius and the height:\n");
scanf_s("%lf %lf", &r, &h);
if (r <= 0 || h <= 0) {
break;
}
printf("%.2f\n", (1.0 / 3) * pi*r*r*h);
break ;
return 1;
}
}
}