求高手帮我看一下这一个c语言程序,到底是哪里出错了。
#include<stdio.h>voidmain(){floatt;printf("inputdatat:");scanf("%f",&t);switch(int(t)...
#include <stdio.h>
void main()
{ float t;
printf("input data t:");
scanf("%f",&t);
switch(int(t))
{ case 6: printf("it is time to get up.\n");
case 7: printf("it is time to go to school\n");
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");
case 12:
case 13:
printf("it is noon.it is time to rest\n");
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");
default:
printf("good night\n");
}
} 展开
void main()
{ float t;
printf("input data t:");
scanf("%f",&t);
switch(int(t))
{ case 6: printf("it is time to get up.\n");
case 7: printf("it is time to go to school\n");
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");
case 12:
case 13:
printf("it is noon.it is time to rest\n");
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");
default:
printf("good night\n");
}
} 展开
5个回答
展开全部
#include <stdio.h>
void main()
{ int t;
printf("input data t:");
scanf("%d",&t);
switch(int(t))
{ case 6: printf("it is time to get up.\n");break;
case 7: printf("it is time to go to school\n"); break; //跳出循环,要不他执行完这句接着执行下面其他case语句
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");break;
case 12:
case 13:
printf("it is noon.it is time to rest\n");break;
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");break;
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");break;
default:
printf("good night\n");break;
}
}
void main()
{ int t;
printf("input data t:");
scanf("%d",&t);
switch(int(t))
{ case 6: printf("it is time to get up.\n");break;
case 7: printf("it is time to go to school\n"); break; //跳出循环,要不他执行完这句接着执行下面其他case语句
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");break;
case 12:
case 13:
printf("it is noon.it is time to rest\n");break;
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");break;
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");break;
default:
printf("good night\n");break;
}
}
追问
运行的时候还是有错,说是调试错误。debug error
追答
你那检查你软件是不是有问题。
展开全部
错误位置: switch(int(t))
错误原因:强制类型转换的格式应该是 (类型)(表达式),需要将类型也用括号括起来:
switch( (int) (t) )
同时,注意在break在switch语句的中的作用与使用。
错误原因:强制类型转换的格式应该是 (类型)(表达式),需要将类型也用括号括起来:
switch( (int) (t) )
同时,注意在break在switch语句的中的作用与使用。
追问
运行的时候还是有错,说是调试错误。debug error
追答
如果还有错误,未必是代码的问题了,可能是你所创建的项目有其他问题。可以重新创建一个新项目,把代码复制过去,重新调试运行看看。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
void main()
{
int t;
printf("input data t:");
scanf("%d",&t);
switch(t)
{ case 6: printf("it is time to get up.\n");
break;
case 7: printf("it is time to go to school\n");
break;
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");
break;
case 12:
case 13:
printf("it is noon.it is time to rest\n");
break;
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");
break;
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");
break;
default:
printf("good night\n");
}
}
switch后括号内必须为整型,你把t直接声明为整型,不要经过类型转换就不报错了
void main()
{
int t;
printf("input data t:");
scanf("%d",&t);
switch(t)
{ case 6: printf("it is time to get up.\n");
break;
case 7: printf("it is time to go to school\n");
break;
case 8:
case 9:
case 10:
case 11:
printf("good morning.\n");
break;
case 12:
case 13:
printf("it is noon.it is time to rest\n");
break;
case 14:
case 15:
case 16:
case 17:
printf("good evening\n");
break;
case 18:
case 19:
case 20:
case 21:
printf("it is time to home and have homework\n");
break;
default:
printf("good night\n");
}
}
switch后括号内必须为整型,你把t直接声明为整型,不要经过类型转换就不报错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
break加在case一行中第一个分号后。
追问
运行的时候还是有错,说是调试错误。debug error
追答
你把错误信息贴出来。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有加break的话,case语句会从上到下执行下去,本程序中会把所有的printf语句执行一遍。
更多追问追答
追问
这个break加在哪里呢,
追答
举个例子:
case 6:
printf("it is time to get up.\n");
break;
那么如果(int)t == 6 的话,那么只执行case6,其后的case语句不执行,直接跳出switch语句
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询