请大佬帮我看看这代码到底哪出问题了。。。

tlidft 2016-12-18 01:37:33
#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;
}
}
}


学校的作业....用vs2015检查没问题 可以运行 但是一提交到作业的网站就各种错误.....实在不知道怎么改了
...全文
125 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ck2333 2016-12-18
  • 打赏
  • 举报
回复
break直接跳出了,根本不会执行你后面的语句。
paschen 2016-12-18
  • 打赏
  • 举报
回复
你代码中的: break ; return 1; 这里根本执行不到return 1, break后就直接退出了switch直接开始下一轮循环
Erwin_Wu 2016-12-18
  • 打赏
  • 举报
回复
跳出while循环后要加return吧,break后面的return走不到可以删掉

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧