该楼层疑似违规已被系统折叠隐藏此楼查看此楼
#include
#include
int main()
{
char sex,sports,diet;
float faHeight,moHeight,Height;
printf("请输入父亲身高\n,请输入母亲身高\n,请输入性别\n");
scanf("%f%f%c",&faHeight,&moHeight,&sex);
switch(sex)
{
case'F':Height=(faHeight+moHeight)*054;printf("%f\n",Height);break;
case'M':Height=(faHeight*0.923+moHeight)/2;printf("%f\n",Height);break;
default:printf("enter data error!\n");
}
printf("%f\n",Height);
scanf("%c%c\n",&diet,&sports);
printf("请输入是否健康饮食,请输入是否适当运动");
switch(diet)
{
case'Y':Height=Height*1.015;printf("%f\n",Height);break;
case'N':printf("%f\n",Height);break;
default:printf("enter data error!\n");
}
printf("%f\n",Height);
switch(sports)
{
case'Y':Height=Height*1.02;;printf("%f\n",Height);break;
case'N':printf("%f\n",Height);break;
default:printf("enter data error!\n");
}
return 0;
}
点赞
一键三连
C语言还提供了另一种用于多分支选择的switch语句, 其一般形式为:switch(表达式){ case常量表达式1: 语句1; case常量表达式2: 语句2; … case常量表达式n: 语句n; default:语句n+1;}其语义是:计算表达式的值。 并逐个与其后的常量表达式值相比较,当表...