PTA 实验10-1 圆形体体积计算器,通过不了,找不到问题

实验10-1 圆形体体积计算器
分数 20
作者 张高燕
单位 浙江大学

输入格式:
在每次计算之前,要求输出如下界面:

1-Ball
2-Cylinder
3-Cone
other-Exit
Please enter your command:
然后从标准输入读进一个整数指令。

输出格式:
如果读入的指令是1或2或3,则执行相应的体积计算;如果是其他整数,则程序结束运行。

当输入为1时,在计算球体体积之前,打印Please enter the radius:,然后读入球体半径,完成计算;
当输入为2时,在计算圆柱体体积之前,打印Please enter the radius and the height:,然后读入底圆半径和高,完成计算;
当输入为3时,在计算圆锥体体积之前,打印Please enter the radius and the height:,然后读入底圆半径和高,完成计算。
计算结果在一行内输出,保留小数点后两位。

输入样例:
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:

这是我的代码,但是找不到问题呀,看看吧。

#include <stdio.h>
#include <math.h>
#define Pi 3.1415926535
void print(void);
void select(int option);
void ball(void);
void cylinder(void);
void cone(void);
int main(void) {
    int option;
    while (1) {
        print();
        scanf("%d", &option);
        if (option < 1 || option > 3) {
            break;
        }
        select(option);
    }
    return 0;
}
void print(void) {
    printf("1-Ball\n");
    printf("2-Cylinder\n");
    printf("3-Cone\n");
    printf("Other-Exit\n");
    printf("Please enter your command:");
}
void select(int option) {
    switch (option) {
        case 1:
            ball();
            break;
        case 2:
            cylinder();
            break;
        case 3:
            cone();
            break;
    }
}
void ball(void) {
    double r, v;
    printf("Please enter the radius:\n");
    scanf("%lf", &r);
    v = 4 * Pi * pow(r, 3) / 3;
    printf("%.2f\n", v);
}
void cylinder(void) {
    double r, h, v;
    printf("Please enter the radius and the height:\n");
    scanf("%lf %lf", &r, &h);
    v = Pi * pow(r, 2) * h;
    printf("%.2f\n", v);
}
void cone(void) {
    double r, h, v;
    printf("Please enter the radius and the height:\n");
    scanf("%lf %lf", &r, &h);
    v = Pi * pow(r, 2) * h / 3;
    printf("%.2f\n", v);
}

改这样试试:

#include <stdio.h>
//#include <math.h>
#include <stdlib.h>
#define Pi 3.1415926535
void print(void);
void select(int option);
void ball(void);
void cylinder(void);
void cone(void);
int main(void) {
    int option;
    while (1) {
        print();
        scanf("%d", &option);
        //if (option < 1 || option > 3) {
        //    break;
        //}
        //select(option);
        switch (option) {
        case 1:
            ball();
            break;
        case 2:
            cylinder();
            break;
        case 3:
            cone();
            break;
        default:exit(0);
        }
    }
    return 0;
}
void print(void) {
    printf("1-Ball\n");
    printf("2-Cylinder\n");
    printf("3-Cone\n");
    printf("Other-Exit\n");
    printf("Please enter your command:");
}
void select(int option) {
    switch (option) {
    case 1:
        ball();
        break;
    case 2:
        cylinder();
        break;
    case 3:
        cone();
        break;
    }
}
void ball(void) {
    double r, v;
    printf("Please enter the radius:\n");
    scanf("%lf", &r);
    v = 4.0 * Pi * r * r * r / 3.0;  //v = 4 * Pi * pow(r, 3) / 3;
    printf("%.2f\n", v);
}
void cylinder(void) {
    double r, h, v;
    printf("Please enter the radius and the height:\n");
    scanf("%lf %lf", &r, &h);
    v = Pi * r * r * h;    //v = Pi * pow(r, 2) * h;
    printf("%.2f\n", v);
}
void cone(void) {
    double r, h, v;
    printf("Please enter the radius and the height:\n");
    scanf("%lf %lf", &r, &h);
    v = Pi * r * r * h / 3.0; //v = Pi * pow(r, 2) * h / 3;
    printf("%.2f\n", v);
}