秋水至寒 2022-10-31 18:10 采纳率: 78.6%
浏览 25
已结题

为什么每次switch结束后就跳出程序了,break不是只对小循环起作用吗

#include <stdio.h>

#include <stdlib.h>

#include<math.h>

#include"BASE.h"

#include"fun_5.h"

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

 

int main(int argc, char *argv[]){

int n,q;

while(1){

printf("Enter 1 to start the program\n");

scanf("%d",&q);

/*if cycle*/

if (q==1){

/*enter function*/

printf( "1.Decimal to Binary\n2Make a pattern output\n3.Determine what triangle it is\n4.Sum of any two digit number\n5.What is the volume of the sphere\n6.How many leap years have you been born\nPlease choose\n");

scanf("%d",&n); 

/*switch cycle*/

switch(n){

case 1:{

    int n,h;

    printf("Please input the number\n");

    scanf("%d",&n);

    h=DecimalToBinary(n);

printf("%d\n",h);

    break;}

case 2:{

    double radius;

 printf("enter radius:");

 scanf("%lf",&radius);

 printf("Volume=%lf\n",Volume(radius));

    break;}

}

}

else

printf("Input error");

break;

}

 return 0;

}

  • 写回答

3条回答 默认 最新

  • 快乐鹦鹉 2022-10-31 18:16
    关注

    最下面的break因该是else的代码块。else下面的两行加大括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月31日
  • 已采纳回答 10月31日
  • 创建了问题 10月31日

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表