求教c语言大神 这道题用switch语言怎么写???
展开全部
switch只能判断常量,你这个输入的是浮点数而且需要判断范围,不能用switch写。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
main()
{
int H=0;
int a=0;
printf("Please input the time:");
scanf("%d",&H);
if(H>=6&&H<7) a=1;
else if(H>=7&&H<8) a=2;
else if(H>=8&&H<11) a=3;
else if(H>=12&&H<13) a=4;
else if(H>=13&&H<17) a=5;
else if(H>=17&&H<21) a=6;
else a=7;
printf("the value of a is :%d\n",a);
switch(a)
{
case 1:printf("It's time to get up and have a shower."); break;
case 2:printf("What a funny time to eat breakfast!"); break;
case 3:printf("Good morning!"); break;
case 4:printf("Lunch time!Happy hour!Sweet smile!"); break;
case 5:printf("Good evening!"); break;
case 6:printf("Happiness is sitting around the family dinner table.");break;
default:printf("Good night!");
}
}
main()
{
int H=0;
int a=0;
printf("Please input the time:");
scanf("%d",&H);
if(H>=6&&H<7) a=1;
else if(H>=7&&H<8) a=2;
else if(H>=8&&H<11) a=3;
else if(H>=12&&H<13) a=4;
else if(H>=13&&H<17) a=5;
else if(H>=17&&H<21) a=6;
else a=7;
printf("the value of a is :%d\n",a);
switch(a)
{
case 1:printf("It's time to get up and have a shower."); break;
case 2:printf("What a funny time to eat breakfast!"); break;
case 3:printf("Good morning!"); break;
case 4:printf("Lunch time!Happy hour!Sweet smile!"); break;
case 5:printf("Good evening!"); break;
case 6:printf("Happiness is sitting around the family dinner table.");break;
default:printf("Good night!");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main(){
doubale a ;
scanf("%lf",&a);
if(a>6&&a<7)
printf("It`s time........");
else if (a>7&&a<8)
printf("what........");
//|
//|
//|
else
printf("Goodnight!");
}
void main(){
doubale a ;
scanf("%lf",&a);
if(a>6&&a<7)
printf("It`s time........");
else if (a>7&&a<8)
printf("what........");
//|
//|
//|
else
printf("Goodnight!");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-04-06
展开全部
自己看书,找个switch的代码自己运行一下就懂了,然后改一下。这样的入门问题如果你不自己先吃点苦,后面有更多的苦要吃的。试试吧,你可以的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int main()
{
int score;
scanf("%d",&score);
switch(score/10)
{
case 10:
case 9:printf("A\n");break;
case 8:printf("B\n");break;
case 7:printf("C\n");break;
case 6:printf("D\n");break;
default:printf("E\n");
}
return 0;
}
int main()
{
int score;
scanf("%d",&score);
switch(score/10)
{
case 10:
case 9:printf("A\n");break;
case 8:printf("B\n");break;
case 7:printf("C\n");break;
case 6:printf("D\n");break;
default:printf("E\n");
}
return 0;
}
追答
嘻嘻!都答非所问!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询